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 upExpand `try!` macro with additional case #1393
Conversation
alexcrichton
added
the
T-libs
label
Dec 5, 2015
This comment has been minimized.
This comment has been minimized.
|
I personally would be more interested in seeing this solved using trait based exception handling, and deprecating |
This comment has been minimized.
This comment has been minimized.
|
@withoutboats IMHO this is bad idea. Error handling in Rust is IMHO great and we should not change that. Language itself should know nothing about error handling, it should be left as is with some additional helpers like this one. |
This comment has been minimized.
This comment has been minimized.
|
Can you please expand the "Motivation" section to actually include motivation? (The Reddit post doesn't really explain it either, but even if it did, the RFCs are supposed to be self-contained). Is it to enable use of |
This comment has been minimized.
This comment has been minimized.
|
@vadimcn exactly. But as I have written in RFC, I am not convinced that this should land in |
This comment has been minimized.
This comment has been minimized.
|
@hauleth: Please put this info into the RFC. It should be clear what and why is being proposed without reading through the comments thread. As for the idea itself, I think it has some merit. It isn't really a silent drop, since I am not sure I like the proposed syntax though: |
This comment has been minimized.
This comment has been minimized.
|
Unfortunately |
This comment has been minimized.
This comment has been minimized.
defuz
commented
Dec 8, 2015
|
I was waiting when someone will offer it, but I'm wondering why you have not offered more general variant, that allows you to do any action in case of an error: macro_rules! try {
($expr:expr) => (match $expr {
$crate::result::Result::Ok(val) => val,
$crate::result::Result::Err(err) => {
return $crate::result::Result::Err($crate::convert::From::from(err))
}
});
($expr:expr => $err:expr) => (match $expr {
$crate::result::Result::Ok(val) => val,
$crate::result::Result::Err(..) => $err
})
}The most frequent places where it is necessary for me are: loop { // or for
// ...
try!(foo() => break)
// ...
}And: loop { // or for
// ...
try!(foo() => continue)
// ...
}You can even write something like this: try!(foo() => return DEFAULT_VALUE)This would be synonymous with try!(foo() => bar())The code which is proposed now will be fully working too: try!(foo() => return) |
This comment has been minimized.
This comment has been minimized.
|
@defuz I was thinking about it. However I think that explicit |
This comment has been minimized.
This comment has been minimized.
|
Essentially, the underlying issue is really the missing ability to define type constraints to expressions in macro definition. Being able to do that, one would be able to define a macro, that act differently from Option and Result. This can be done in a non-breaking manner along with the new macro definition syntax. |
This comment has been minimized.
This comment has been minimized.
|
@ticki macro expansion occurs at an early stage of compilation in which expressions are not typed. A feature that could be useful here and other places though is the ability to define some kind of polymorphic destructuring. |
This comment has been minimized.
This comment has been minimized.
|
@withoutboats Makes sense. I wonder what implications it would have to expand certain macros (with type constraints) later on. |
This comment has been minimized.
This comment has been minimized.
defuz
commented
Dec 8, 2015
|
@hauleth What is the principal difference between I think that the basic idea of this proposal is allowed to perform control flow statements ( Perhaps allowed to do Also, I don't see any reason why a possible return value should be only |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I don't think it's wise to bake a feature into the |
This comment has been minimized.
This comment has been minimized.
|
It isn't wise. It is just discussion about how many people are for or against it. |
alexcrichton
assigned
aturon
Jan 21, 2016
aturon
added
the
I-nominated
label
Feb 2, 2016
This comment has been minimized.
This comment has been minimized.
|
The libs team feels that we are likely to not merge this for now in light of trait-based exception handling having recently landed. We're likely to change |
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Feb 11, 2016
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this RFC during triage yesterday and the conclusion was to close (in the face of trait-based exception handling). Thanks again though for the RFC @hauleth! |
hauleth commentedDec 5, 2015
As it is suggested in Reddit post I suggests
try!($expr => return)macro to return earlier from function returning
()and discardErr(…)value.As honestly I am not sure about this feature, but I think that community should
decide about it.
Rendered