eRFC: if- and while-let-chains, take 2 - #2497
Conversation
commented
Jul 13, 2018
|
I am very for this change. This syntax feels natural and intuitive, and it is something I've pined for. My remarks are:
|
commented
Jul 13, 2018
Thank you for the data point and the remarks. I think the primary motivation for also changing That said, if we consider iterating over multiple sources that produce elements in a zip-like fashion (but not strictly
I'm personally undecided on adding |
|
@aturon has asked me to clarify what exactly is being proposed to be accepted with this RFC. So here goes... The precedent set by closing RFCs #2443, #2441, and #2429 is that we don't accept RFCs reserving syntax without accepting a feature along with it. Therefore, to be consistent with this policy, and for the purposes of making So the idea with this RFC is that we accept the full feature now (the idea of chaining...), but leave finalizing the syntax itself unresolved-ish as we did with #2071 ( After the Rust 2018 has shipped, and when we have time, we can then implement the proposed syntax and experiment with it on nightly. The syntax will still have to be finalized by some other decision, such as with another RFC or on the tracking issue. |
|
My opinion hasn't changed since #2260 (comment). We should aim for supporting a convenient non-exhaustive pattern-matching expressions in general (
That's just not true, for expressions in If "slow to develop" refers to my promise to write an RFC for pattern-matching expressions |
commented
Jul 13, 2018
|
@petrochenkov Totally understood -- did you see @Centril's clarifying comment? My understanding is that this RFC is meant to commit us to (1) some solution to this problem and (2) carving out a bit of space in the grammar so that the solution could be as discussed in the RFC. FWIW, I also have significant misgivings about solving this problem by essentially extending the special-cased treatment of @Centril I wonder if this should be made formally an "eRFC" to signify more clearly the issues above? |
commented
Jul 13, 2018
|
@aturon |
commented
Jul 13, 2018
|
These operators all have lower precedence than
Which means we also have the following ambiguity to consider: if let Range { start: _, end: false } = true..true && false {
println!("(current behavior)");
} else {
panic!();
} let result = loop {
if let Some(0u32) = break true && false {
panic!();
}
panic!();
};
assert_eq!(result, false);And then const F: fn() -> bool = || true;
if let Range { start: F, end } = F..|| false {
println!("(current behavior)");
assert!(!end());
} else {
panic!();
} let t = &&true;
if let Range { start: true, end } = t..&&false {
println!("(current behavior)");
assert_eq!(**end, false);
} else {
panic!();
}Please also ensure the parser accepts the following: if a || b {} // <-- no parenthesis, it is ok.
if a && b || c && d {}
// interpret as: `(a && b) || (c && d)`and rejects the following before if let Some(a) = b && c || d {}
// interpret as: `((let Some(a) = b) && c) || d` |
commented
Jul 13, 2018
|
@aturon eRFC it is ;) @petrochenkov Yep, it's about making the proposed solution possible and recognizing that some solution (which could be I would personally be fine with experimenting with
I see; my impression was that it was more complicated from the discussions at #2260. This is the "bindings only live until the end of a full expression" rule?
Not at all :) It is referring to my perception of the support for
I thank you for it ❤️ |
commented
Jul 13, 2018
|
I can't say I'm a huge fan of the specific proposed syntax, but I'm inclined to take this step regardless, so that even if we don't end up going with this particular syntax we can detect potentially ambiguous uses of it. I'm honestly tempted to argue that either grouping should require parentheses. Minor nit: for consistency, can you please always put Also, in the example of how |
commented
Jan 31, 2019
|
In the code you showed, you could have used a guarded match. That’s already part of the language and it will do the job for most cases. Having lazy pattern-matching mixed with booleans makes me incomfortable. I’m not saying I’m against lazy pattern-matching (it’s actually handy). I’m just saying that using the |
commented
Dec 6, 2024
|
Can somebody explain to me why the Swift |
|
@alper It was considered and the community highly disliked it. There is literally a survey report inside the RFC document. |
🖼️ Rendered
⏭ Tracking issue - Main
⏭ Tracking issue - Edition transitioning
📝 Summary
Extends
if letandwhile let-expressions with chaining, allowing you to combine multiplelets andbool-typed conditions together naturally. After implementing this RFC, you'll be able to write, among other things:The main aim of this RFC is to decide that this is a problem worth solving as well as discussing a few available options. Most importantly, we want to make
let PAT = EXPR && ..a possible option for Rust 2018.💖 Thanks
To everyone who participated in RFC #2260 and to the survey participants.
To @scottmcm for collaborating with me on the original RFC.
To @aturon and @nikomatsakis for taking the time to discuss this with me.
To @SergioBenitez for checking the feasibility of this in Rust 2018.
To @oli-obk for providing me with the useful example in the summary ;)
To @joshtriplett for the consultation on the style.
To @kennytm for improving clarity on the Rust 2018 migration technical changes.