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 upExplicit refutable `let`: `let`..`else` #373
Comments
This comment has been minimized.
This comment has been minimized.
|
I don't like the idea of having to scan ahead in the program text for Is there some way we could revise our |
This comment has been minimized.
This comment has been minimized.
|
(also, I'm worried about the RFC repo issue database creeping into http://discuss.rust-lang.org/ territory ... if you are unhappy with the discuss interface, or think that it is not a good area for proposing sketches of language features, then we should discuss that and try to address it.) |
This comment has been minimized.
This comment has been minimized.
sinistersnare
commented
Oct 8, 2014
|
I agree, this is the wrong place for "ideas", something like this belongs in the discourse forum. |
This comment has been minimized.
This comment has been minimized.
Most of the time this should be apparent from the pattern itself, though. I asked @aturon about that on IRC:
Perhaps I phrased my question, or interpreted the response incorrectly, but this in particular falls under the latter. I don't want to have a design discussion about this right now in preparation for an RFC (I intentionally want to "get it off my plate" so I can work on more important things); I just want there to be a public record of the idea where others can see it and it doesn't get lost. I feel that a GitHub issue is more appropriate for this than the forum. (And in any case, if I have to expend more effort on thinking about where to post things than on the thing I want to post... feel free to move it.) |
This comment has been minimized.
This comment has been minimized.
|
I think the policy on this is a work in progress (since we just started using this issue tracker a couple of weeks ago). We migrated a bunch of stuff from the We've been having a bit of forum/process churn, so it sounds like the Rust Team needs to nail down (and write up) the policy for what goes where. Anyway, sorry @glaebhoerl for the policy pushback; my fault. |
This comment has been minimized.
This comment has been minimized.
|
Filed #375 for the meta-discussion. |
glaebhoerl
referenced this issue
Oct 8, 2014
Closed
META: clarify when an RFCs issue is appropriate #375
This comment has been minimized.
This comment has been minimized.
|
In the meantime Swift has added an analogous feature in the form of Another way to express this functionality which recently occurred to me would be to invert
So where EDIT: This would also extend cleanly to |
glaebhoerl
referenced this issue
Oct 2, 2015
Closed
Add a `let...else` expression, similar to Swift's `guard let...else` #1303
This comment has been minimized.
This comment has been minimized.
fschutt
commented
Jan 12, 2018
|
Another idea would be something like this:
or:
Meaning, the thing in the "unwrap_or" is an expression that gets evaluated (meaning "continue" in itself is an expression). Like "continue" being a value.
Just an idea. |
Centril
added
the
T-lang
label
Jan 12, 2018
This comment has been minimized.
This comment has been minimized.
Wyverald
commented
Jun 27, 2018
|
Is there an RFC related to this issue? I'd really love to see this feature. |
This comment has been minimized.
This comment has been minimized.
|
There was: #1303 |
glaebhoerl commentedOct 8, 2014
Our
lets are currently irrefutable. This is good. We could also have refutablelets with an explicitelseclause:In the simplest formulation, there would be a single
elseclause with the argument being anything of type!(break,return,panic!, etc.). More sophistication is possible with chainedelseclauses, where multiple RHSs are tried in succession, with only the last one required to be of type!; and by also allowing a literal or constant which definitely matches rather than just an!(so in the above example,else Ok(9), for instance).The use case for this overlaps with
if let, but not completely.if letinvolves rightward drift, and is appropriate if you want access to e.g. the value in anOptionfor a short period, and then to do other things afterwards, or if you want to handle theelsecase by something other than exiting.let..elseavoids rightwards drift and is appropriate if you want to early-escape from the whole computation when the pattern doesn't match.The potential for syntactic ambiguity with
if..elseneeds to be thought through. But I don't believe there is an actual problem:If we interpret this as being an
ifexpression without anelseblock, and theelseblock as belonging to thelet, that ends up being contradictory:ifexpressions have type(), which is never refutable, and so doesn't make any sense as the type of PAT in a refutablelet. So the only sensible way to interpret this is as anif-elseexpression on the RHS.Earlier discussion on the mailing list.