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 upUse a Carrier trait with the `?` operator #33389
Conversation
rust-highfive
assigned
alexcrichton
May 3, 2016
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
nrc
force-pushed the
nrc:carrier
branch
from
691c688
to
bb8e59e
May 3, 2016
This comment has been minimized.
This comment has been minimized.
|
The big thing for me isn't Result <-> Option -- I'd like to experiment with some kind of DebugResult that builds up a backtrace as it passes through question marks. |
jimmycuadra
reviewed
May 3, 2016
| @@ -2155,3 +2157,126 @@ pub trait BoxPlace<Data: ?Sized> : Place<Data> { | |||
| /// Creates a globally fresh place. | |||
| fn make_place() -> Self; | |||
| } | |||
|
|
|||
| /// A trait for types which have success and error states and are meant to work | |||
| /// with the quiestion mark operator. | |||
This comment has been minimized.
This comment has been minimized.
nrc
force-pushed the
nrc:carrier
branch
from
bb8e59e
to
0de7b23
May 3, 2016
alexcrichton
added
the
T-libs
label
May 4, 2016
durka
reviewed
May 4, 2016
| } | ||
|
|
||
| fn g(x: i32) -> MyResult<i32, String> { | ||
| let _y = f(x)?; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nrc
May 4, 2016
Author
Member
it terminates with the given input, I don't care too much about it being a sensible program
This comment has been minimized.
This comment has been minimized.
durka
May 4, 2016
Contributor
Yeah, it terminates with a stack overflow...
On May 4, 2016 4:49 PM, "Nick Cameron" notifications@github.com wrote:
In src/test/run-pass/try-operator-custom.rs
#33389 (comment):
MyResult::Terrible(e) => T::from_error(e.into()),}- }
+}
+fn f(x: i32) -> Result<i32, String> {
- if x == 0 {
Ok(42)- } else {
let y = g(x)?;Ok(y)- }
+}
+fn g(x: i32) -> MyResult<i32, String> {
- let _y = f(x)?;
it terminates with the given input, I don't care too much about it being a
sensible program—
You are receiving this because you commented.
Reply to this email directly or view it on GitHub
https://github.com/rust-lang/rust/pull/33389/files/0de7b23ac739307c71249116d106c5d074f30b23#r62111982
This comment has been minimized.
This comment has been minimized.
durka
reviewed
May 4, 2016
| @@ -1566,16 +1558,25 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> { | |||
| // to: | |||
| // | |||
| // { | |||
| // match <expr> { | |||
| // match { Carrier::translate( { <expr> } ) } { | |||
This comment has been minimized.
This comment has been minimized.
durka
May 4, 2016
Contributor
I'm worried about this part of the desugaring. Carrier::translate consumes the value, so the Result-ish-thing is completely destroyed and then rebuilt when leaving the match statement. This precludes writing a carrier that would like to carry something more than the success/error values (for example, a backtrace). I am wondering if there is a way we can thread some more user-configurable state through the question marks.
This comment has been minimized.
This comment has been minimized.
glaebhoerl
May 18, 2016
Contributor
For the record the idea that any error Carrier/ResultCarrier type should be isomorphic to Result was very intentional. (Not suggesting that this is therefore beyond debate. Just that it wasn't an oversight.)
nrc
force-pushed the
nrc:carrier
branch
2 times, most recently
from
e89b9e4
to
79a1f5c
May 4, 2016
huonw
reviewed
May 9, 2016
| where T: Carrier<Success=U, Error=V> | ||
| { | ||
| match self { | ||
| Ok(u) => T::from_success(u.into()), |
This comment has been minimized.
This comment has been minimized.
huonw
May 9, 2016
Member
It seems to me that these intos are useless: they're always "converting" from U to U, and V to V. Maybe the signature of translate wants to be something like:
fn translate<T>(self)
where T: Carrier<Success = Self::Success>,
Self::Error: Into<T::Error>,(The thinking being converting the main value implicitly is not nearly as desirable as converting the error one.)
This comment has been minimized.
This comment has been minimized.
nrc
May 10, 2016
Author
Member
I think the signature is OK, but the intos shouldn't be there. I started with a more flexible approach, but decided it wasn't necessary. I think the intos are left over from that. Not really sure why it even compiles.
This comment has been minimized.
This comment has been minimized.
huonw
May 10, 2016
Member
Makes sense.
Not really sure why it even compiles.
T: Into<T> for all (sized) T:
Lines 231 to 243 in 0e7cb8b
nrc
added
T-lang
I-nominated
S-waiting-on-crater
labels
May 10, 2016
nrc
force-pushed the
nrc:carrier
branch
from
79a1f5c
to
937f024
May 10, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
FWIW newer versions of the RFC called this |
This comment has been minimized.
This comment has been minimized.
|
Crater run results: https://gist.github.com/nikomatsakis/eff9c3cb0d79e95b073283369ab37b01
|
This comment has been minimized.
This comment has been minimized.
|
The 1 regression appears to be a timeout (false positive). |
This comment has been minimized.
This comment has been minimized.
|
The language team decided that we should accept this PR, on the understanding that it is for experimentation and will have a period of discussion and examination before FCP. This discuss thread has more details. |
nrc
removed
I-nominated
S-waiting-on-crater
labels
May 18, 2016
This was referenced May 18, 2016
nrc
force-pushed the
nrc:carrier
branch
from
937f024
to
f9ff8d3
May 18, 2016
This comment has been minimized.
This comment has been minimized.
|
ping @alexcrichton see comment above from the lang team, also rebased. |
This comment has been minimized.
This comment has been minimized.
|
This does not seem to change Otherwise, +1 :-) I hope this goes in. |
diwic
reviewed
May 18, 2016
| /// The type of the value when computation succeeds. | ||
| type Success; | ||
| /// The type of the value when computation errors out. | ||
| type Error; |
This comment has been minimized.
This comment has been minimized.
diwic
May 18, 2016
Contributor
Perhaps EarlyReturn could be a better name than Error, as it more closely resembles what actually happens? Returning early does not have to be an error.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
rust-highfive
assigned
aturon
and unassigned
alexcrichton
May 18, 2016
This comment has been minimized.
This comment has been minimized.
|
Sorry for the delayed writeup. The libs team also talked about this PR, and a number of team members felt uncomfortable merging based on the accepted RFC, strongly preferring to amend the RFC with an explicit route for experimentation, especially given the contentious nature of the original RFC. Personally, I can see arguments on both sides, and I think the high-order bit here is that the broader community needs some clear opportunity to weigh in -- whether via an RFC amendment or the new discuss threads. Given that the two teams reached different conclusions, I propose escalating this decision to the core team, and am tagging accordingly. We'll be meeting today. |
aturon
added
the
T-core
label
May 18, 2016
This comment has been minimized.
This comment has been minimized.
|
We discussed the situation in the core team meeting, and the TL;DR is that we believe an amendment RFC needs to happen before this PR is landed. While not everyone agreed that it was strictly necessary, it is the conservative choice, which seems prudent given how contentious the original RFC was. (Sorry @nrc!) The core issue is that the original RFC did not lay out specific plans for expansion here, and while the lang team did say that we would "revisit" the question prior to stabilization, there were no details about that process. Those opposed to this generalization did not push hard on that point in the original RFC because it was taken off the table. And at least some people don't consider this generalization to be something that needs experimental evidence to decide, but rather is a question of mental model for the feature. In the future, any "planned expansions" should be clearly laid out in the RFC and made part of the tracking issue. It's unclear whether the amendment RFC should await some consensus on the discuss thread, or should be started now to drive traffic in that direction. I'll cross-post there for the time being. |
This comment has been minimized.
This comment has been minimized.
|
@nrc ping (just cleaning out some old PRs) Should we close this for now? |
This comment has been minimized.
This comment has been minimized.
|
Yeah, I guess so, we're not going to merge it without an RFC, so may as well close in the meantime |
nrc commentedMay 3, 2016
Allows use with
Optionand customResult-like types.Note that this part of RFC 243 did not get approved, so this PR is just for experimentation purposes.
This supports conversion between result types when they have the same number of type args, but not otherwise (e.g,
ResulttoOption), that requires #33108Part of #31436