Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImpl Try for Option #42526
Conversation
rust-highfive
assigned
alexcrichton
Jun 8, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
kennytm
reviewed
Jun 8, 2017
| /// The `Option` type. See [the module level documentation](index.html) for more. | ||
| #[unstable(feature = "try_trait", issue = "42327")] | ||
| #[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] | ||
| pub struct Missing; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
huntiep
Jun 8, 2017
Author
Contributor
Yes, I needed something there in order to compile and forgot to change it. I'm not sure what to replace it with; maybe The equivalent of Option::None for a Result type.?
This comment has been minimized.
This comment has been minimized.
|
This is exciting, and applying right after branching for release is probably the best option we have for insta-stable things like this. (This will allow Something I didn't want to push in the RFC discussion, but thought interesting: what about a That's intentionally non-constructible for now, since what I think it ought to be is Though I guess the type will stay unstable for a while, so it doesn't matter for now... |
oli-obk
reviewed
Jun 8, 2017
| assert_eq!(try_option_none(), None); | ||
|
|
||
| fn try_option_ok() -> Result<u8, Missing> { | ||
| let val = Ok(1)?; |
This comment has been minimized.
This comment has been minimized.
oli-obk
Jun 8, 2017
Contributor
This is not going through the Option. I already works now... Maybe you meant to use Some here?
oli-obk
reviewed
Jun 8, 2017
| assert_eq!(try_option_ok(), Ok(1)); | ||
|
|
||
| fn try_option_err() -> Result<u8, Missing> { | ||
| let val = Err(Missing)?; |
This comment has been minimized.
This comment has been minimized.
oli-obk
reviewed
Jun 8, 2017
| assert_eq!(try_result_none(), None); | ||
|
|
||
| fn try_result_ok() -> Result<u8, u8> { | ||
| let val = Ok(1)?; |
This comment has been minimized.
This comment has been minimized.
oli-obk
Jun 8, 2017
Contributor
This is also nothing new... maybe change it into a compile-fail test by using Some/None and triggering a compilation error
This comment has been minimized.
This comment has been minimized.
huntiep
Jun 8, 2017
Author
Contributor
I didn't see any tests for Result's Try implemenation, but if they exist I can remove these tests.
nikomatsakis
referenced this pull request
Jun 8, 2017
Open
Tracking issue for `?` operator and `try` blocks (RFC 243, `question_mark` & `try_blocks` features) #31436
This comment has been minimized.
This comment has been minimized.
|
r? @aturon Also cc @rust-lang/lang, especially @scottmcm's comment where I think this is insta-stable |
rust-highfive
assigned
aturon
and unassigned
alexcrichton
Jun 8, 2017
alexcrichton
added
the
S-waiting-on-review
label
Jun 8, 2017
This comment has been minimized.
This comment has been minimized.
|
I think one way to prevent it from being insta-stable would be to make it I am open to bikeshedding the name of |
This comment has been minimized.
This comment has been minimized.
MoSal
commented
Jun 10, 2017
|
Maybe |
This comment has been minimized.
This comment has been minimized.
frewsxcv
added
the
T-libs
label
Jun 11, 2017
This comment has been minimized.
This comment has been minimized.
|
@kennytm well that was more about a public "cfg", but yeah apparently we don't have |
arielb1
added
S-waiting-on-author
and removed
S-waiting-on-review
labels
Jun 13, 2017
This comment has been minimized.
This comment has been minimized.
|
I also like At this point what do I need to do? |
This comment has been minimized.
This comment has been minimized.
|
I think we should settle on the name -- I am not 100% sure when we should merge this RFC though. The insta-stable thing bothers me, but I don't have a good idea what else to do about it. |
This comment has been minimized.
This comment has been minimized.
|
@rust-lang/lang @rust-lang/libs -- anybody care to "weigh in" on the name of the "error type" to use in the |
This comment has been minimized.
This comment has been minimized.
|
If we follow the naming practice in libstd, it should be |
This comment has been minimized.
This comment has been minimized.
|
What's the reason not to use |
This comment has been minimized.
This comment has been minimized.
|
@withoutboats rust-lang/rfcs#1859 explained why the error must be a dedicated type (to prevent accidentally ?-returning an |
This comment has been minimized.
This comment has been minimized.
|
I think
Any thoughts on how to better document this, regardless of what the final name is? |
This comment has been minimized.
This comment has been minimized.
|
Ergonomically at least this seems most likely to arise in something like: impl From<Missing> for MyErrorType(if at all). That way you could |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
The feeling was that enum List<T> {
Nil,
Cons(T, Box<List<T>>),
}Imagine that I implemented |
This comment has been minimized.
This comment has been minimized.
|
"The error type that results from applying the try operator ( |
huntiep
added some commits
Jun 8, 2017
aidanhs
added
S-waiting-on-review
and removed
S-waiting-on-author
labels
Sep 28, 2017
nikomatsakis
force-pushed the
huntiep:try_opt
branch
from
10fc9fb
to
e30d92b
Sep 28, 2017
This comment has been minimized.
This comment has been minimized.
|
@huntiep I took the liberty of rebasing for you. |
nikomatsakis
approved these changes
Sep 28, 2017
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis I'm sorry, I missed that part of your last comment. For future reference, can you briefly explain what you meant by rebase? |
This comment has been minimized.
This comment has been minimized.
|
@huntiep it refers to |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis did you mean to review at bors? |
This comment has been minimized.
This comment has been minimized.
|
@bors: r=nikomatsakis |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Sep 29, 2017
This comment has been minimized.
This comment has been minimized.
|
|
huntiep commentedJun 8, 2017
This is part of #31436.