-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking Issue for io_error_downcast
#99262
Comments
@rust-lang/libs-api I'd like to push for stabilisation of this feature. The only thing I'm not sure about is the return value |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
Stablisation ReportImplementation History
API SummaryA summary of the API is included in the description of this issue. Experience Reportn/a |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
@rustbot label +S-waiting-on-team |
@rust-lang/libs-api: https://doc.rust-lang.org/nightly/std/io/struct.Error.html#method.downcast impl std::io::Error {
pub fn downcast<E>(self) -> Result<Box<E>, Self>
where
E: Error + Send + Sync + 'static
} Signature resembles these existing stable ones: impl Box<dyn Any> {
pub fn downcast<T>(self) -> Result<Box<T>, Self>
where
T: Any
}
impl dyn Error {
pub fn downcast<T>(self: Box<Self>) -> Result<Box<T>, Box<Self>>
where
T: Error + 'static
} |
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@rfcbot concern docs The docs here I think should be beefed up a bit. I see a few things worth improving:
|
@rfcbot concern box @NobodyXu mentioned a question above about returning a Also, AIUI, an |
I was worried about that For example, it could change In that case, returning
Yes, But TBF,
Yes, that's right.
Well, I don't think we need support for
In the future where it might be supported, but in practice I rarely seen I think it makes more sense to remove the
Yes.
Won't that leak the internal into the API? There are actually 4 ways of constructing
The first 3 are public and can be done by everybody, the last one is Also, it's hard to explain that there is a
Yes, I can submit a PR to improve its doc once we settle on whether to remove the
I don't think this is necessary though. Putting convenience aside, using
I actually have an example of this from impl From<io::Error> for BinstallError {
fn from(err: io::Error) -> Self {
if err.get_ref().is_some() {
let kind = err.kind();
let inner = err
.into_inner()
.expect("err.get_ref() returns Some, so err.into_inner() should also return Some");
inner
.downcast()
.map(|b| *b)
.unwrap_or_else(|err| BinstallError::Io(io::Error::new(kind, err)))
} else {
BinstallError::Io(err)
}
}
} As you can see, it has to call I haven't checked the generated assembly, the optimizer might be smart enough to optimize these heap allocation out. But that isn't a guarantee and crates like |
@NobodyXu We discussed this in the libs-api meeting. We think that we can move forward with the FCP once the changes proposed by @BurntSushi are addressed:
|
… r=m-ou-se Update `std::io::Error::downcast` return type and update its doc according to decision made by rust libs-api team in rust-lang#99262 (comment)
Rollup merge of rust-lang#120117 - NobodyXu:99262/update-api-and-doc, r=m-ou-se Update `std::io::Error::downcast` return type and update its doc according to decision made by rust libs-api team in rust-lang#99262 (comment)
Update `std::io::Error::downcast` return type and update its doc according to decision made by rust libs-api team in rust-lang/rust#99262 (comment)
Stablisation ReportImplementation History
API Summaryhttps://doc.rust-lang.org/nightly/std/io/struct.Error.html#method.downcast impl std::io::Error {
pub fn downcast<E>(self) -> Result<E, Self>
where
E: Error + Send + Sync + 'static,
} signature resembles existing stable ones: impl Box<dyn Any> {
pub fn downcast<T>(self) -> Result<Box<T>, Self>
where
T: Any
}
impl dyn Error {
pub fn downcast<T>(self: Box<Self>) -> Result<Box<T>, Box<Self>>
where
T: Error + 'static
} Experience Reportn/a |
Update `std::io::Error::downcast` return type and update its doc according to decision made by rust libs-api team in rust-lang/rust#99262 (comment)
@BurntSushi I believe your concerns have now been addressed |
@rfcbot resolve box |
I think my docs concerns have not been fully addressed here. The docs for this routine seem both too sparse and too odd to me. I'll try to respond to the bits of @NobodyXu's comment above that I think are relevant here.
No. I'm certainly not asking that the documentation of a type discuss its internal representation. What I'm asking for is a contract that doesn't involve wording like, "you have to have called this method to get this guarantee." Like, I grant there are some situations in which it can make sense to use wording like that, but it's IMO bad juju to start phrasing API contracts in terms of sequences of function calls. It's rather inflexible. And while you enumerated the list of possible constructors today, that isn't necessarily an exhaustive list for all time. Indeed, it's already wrong! (Where "it" is the docs as written today. I see that you mention Instead, I'd rather see the phrasing be something like this: "when this contains a custom boxed error, downcasting will be attempted on the boxed error."
I'm not really sure how to interpret this response, but the point of saying this is to orient the user's understanding of a routine in terms of another one. That is, it's useful to be able to say, "this doesn't introduce any new expressive power, but is instead a convenience routine for some other thing." Please add this to the docs. I also still see a couple of other problems with the docs:
|
@BurntSushi I have opened #123851, would like you to have a look
NOTE that this is actually copied from |
Update document for std::io::Error::downcast Resolve concern raised by `@BurntSushi` rust-lang#99262 (comment)
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Update document for std::io::Error::downcast Resolve concern raised by `@BurntSushi` rust-lang/rust#99262 (comment)
Tracking issue rust-lang#99262
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
Stablise io_error_downcast Tracking issue rust-lang#99262 Closes rust-lang#99262 FCP completed in rust-lang#99262 (comment)
Rollup merge of rust-lang#124076 - NobodyXu:patch-1, r=dtolnay Stablise io_error_downcast Tracking issue rust-lang#99262 Closes rust-lang#99262 FCP completed in rust-lang#99262 (comment)
Update `std::io::Error::downcast` return type and update its doc according to decision made by rust libs-api team in rust-lang/rust#99262 (comment)
Feature gate:
#![feature(io_error_downcast)]
This is a tracking issue for new API
std::io::Error::downcast
.Existing APIs requires two separate calls to obtain the raw os error or the inner error and they both return
Option
.Thus, users would have to first call
Error::get_ref
to check that we indeed has an inner error and checked that itis
the type we expected.Users cannot use
std::io::Error::into_inner
becuase takes the error by value and returnsOption<Box<dyn Error + Send + Sync>>
instead ofResult<Box<dyn Error + Send + Sync>, Self>
.They also cannot workaround this issue by calling
Error::raw_os_error
, since theio::Error
can also be constructed usingimpl From<ErrorKind> for Error
or using other internal methods only accessible by the std library.This new feature
io_error_downcast
solved this issue by providing new APIstd::io::Error::downcast
to downcast the inner error easily withoutunwrap
orexpect
.Public API
Steps / History
try_downcast_inner
tostd::io::Error
libs-team#57downcast
tostd::io::Error
#98387std::io::Error::downcast
return type and doc: Updatestd::io::Error::downcast
return type #120117Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: