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 upextend `?` to operate over other types #1859
Conversation
nikomatsakis
added
the
T-lang
label
Jan 19, 2017
This comment has been minimized.
This comment has been minimized.
|
I don't know how to make a "rendered" link anymore. =) |
This comment has been minimized.
This comment has been minimized.
shepmaster
reviewed
Jan 19, 2017
| @@ -0,0 +1,478 @@ | |||
| - Feature Name: (fill me in with a unique ident, my_awesome_feature) | |||
| - Start Date: (fill me in with today's date, YYYY-MM-DD) | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
shepmaster
reviewed
Jan 19, 2017
| ### What to name the trait | ||
|
|
||
| A number of names have been proposed for this trait. The original name | ||
| was `Carrier`, as the trait "carrier" an error value. A proposed |
This comment has been minimized.
This comment has been minimized.
shepmaster
Jan 19, 2017
Member
I'm unclear if
as the trait "carrier" an error value
Is a typo or an example of why the previous name was poor. I'd have expected "carries".
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Thank you @nikomatsakis! I am excited to watch the progress of this RFC!
Depending on the level of detail envisioned, I'd argue that doing this may be too much. Explicit return types already seem different enough from the exception-like handling that many newcomers are used to; expanding the universe immediately by making it generic might be overwhelming. I'd lean towards a throwaway sentence that indicates that the behavior of
I don't have a strong opinion on implementing |
This comment has been minimized.
This comment has been minimized.
|
TL;DR: I'm OK with
In the lead-up to the RFC, I expressed mild concern at the use of My main concern is against using |
This comment has been minimized.
This comment has been minimized.
|
A very common problem that new rustaceans hit is trying to use I totally understand if this RFC is orthogonal to the issue I'm interested in :) EDIT: Aha, found the discussion more focused on |
This comment has been minimized.
This comment has been minimized.
|
I personally think that enum TryResult<T, R> {
Yield(T),
Return(R),
}Than |
This comment has been minimized.
This comment has been minimized.
I agree we need to correct the error message. I also think that it's worth thinking and drafting error messages here, in this RFC -- too often we leave it as an afterthought. Do you have suggestions for the wording? That said, when you wrote "Seems like that will be a totally separate RFC than this one, correct?", I'd say that this is the overkill. That is, we can (and do!) improve error messages without the need for RFCs. I would think the message would be something like:
We could also go further and analyze the type to which I can add some text to this effect. UPDATE: Done. |
This comment has been minimized.
This comment has been minimized.
|
@shepmaster @clarcharr Regarding the use of
Indeed, I would remove |
This comment has been minimized.
This comment has been minimized.
|
Ah, @clarcharr, regarding the names |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis Personally I think that throwway types are one of the things that makes Rust really powerful. In projects I tend to use enums extensively even if they only have two variants, because I think it makes things more clear, and they're not as equivalent to As far as Yield goes, maybe Continue? |
This comment has been minimized.
This comment has been minimized.
Oh, I guess in my head improving the error message seems tied up with this discussion about treating
That would be better than what's currently there, definitely. I'd also like a companion note that makes a recommendation like "Consider extracting the code where you want to use the
So I don't think "consider changing the return type to a Result" is an appropriate suggestion for I do like what you have in the text for the case when someone tries to use |
This comment has been minimized.
This comment has been minimized.
I agree, although my preference would be to implement the solutions proposed in this thread on internals, such that you could change the return type on
In any case, good point, I see no reason we cannot distinguish the context. In the case of a trait, one could also imagine that, in the case that the trait is thread-local, suggesting that one might consider modifying the trait itself.
To me it seems like overkill. In the first case, it doesn't seem worth mentioning types that do implement try, since the value in question is not of those types. In the second, it's not clear that implementing try is a good idea (or even possible, given the coherence rules). |
This comment has been minimized.
This comment has been minimized.
|
@carols10cents updated to address your latest suggestions |
This comment has been minimized.
This comment has been minimized.
Ah, I overlooked this. I don't quite understand what pattern you are suggesting, can you maybe given an example? |
This comment has been minimized.
This comment has been minimized.
|
When |
This comment has been minimized.
This comment has been minimized.
Oh, I just mean like in this comment, where your
and then |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Agreed.
I see. It seems to me that this is a lot to fit into the immediate error message, but it might be a good candidate for the extended error message. |
This comment has been minimized.
This comment has been minimized.
|
nit: I think line 300 is meant to say "then we should NOT make this suggestion"? |
This comment has been minimized.
This comment has been minimized.
|
<3 love the latest changes in f89568b, this looks great now :) |
This comment has been minimized.
This comment has been minimized.
|
Quick remark: for readers from the future that will discover this RFC through the feature it might be interesting to add a note on why it's |
This comment has been minimized.
This comment has been minimized.
This is I think what this text was meant to convey:
but I guess I should make the connection to |
bluss
referenced this pull request
May 6, 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.
stbuehler
commented
May 8, 2017
|
Thx @bluss for pointing me here. I asked in rust-lang/rust#31436 why the conversion was implemented using I thought I needed |
aturon
removed
the
final-comment-period
label
May 11, 2017
This comment has been minimized.
This comment has been minimized.
|
ping @pnkfelix needs signoff - #1859 (comment) (I want my glorious |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot reviewed |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
May 17, 2017
|
|
rfcbot
added
the
final-comment-period
label
May 17, 2017
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
May 27, 2017
|
The final comment period is now complete. |
|
|
||
| ```rust | ||
| fn foo() -> Poll<T, E> { | ||
| let x = bar()?; // propogate error case |
This comment has been minimized.
This comment has been minimized.
|
|
||
| ```rust | ||
| fn foo() -> Result<T, E> { | ||
| let x = bar()?; // propogate error case |
This comment has been minimized.
This comment has been minimized.
scottmcm
referenced this pull request
May 28, 2017
Merged
Lower `?` to `Try` instead of `Carrier` #42275
nikomatsakis
merged commit 80db2d9
into
rust-lang:master
May 30, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks all. I've merged the RFC and re-used the existing tracking issue. |
nikomatsakis commentedJan 19, 2017
•
edited by mbrubeck
Introduce a trait
Tryfor customizing the behavior of the?operator when applied to types other thanResult.Fixes #1718.
Rendered: https://github.com/rust-lang/rfcs/blob/master/text/1859-try-trait.md
[edited to link to final rendered version]