-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confusing error now saying let
(not if let
) is an expression, rather than a statement, which contradicts the book
#65254
Comments
Also added notes in So the new compiler error, introduced in #60861, here is by design and tested in https://github.com/rust-lang/rust/blob/master/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.rs which has more notes. Specifically, the error here comes from HIR lowering. The idea is that Expr =
| ...
| "if" ExprWithLet Block {"else" Block}?
| {Label ":"}? "while" ExprWithLet Block
;
ExprWithLet =
| "let" PatTop "=" Expr
| ExprWithLet "&&" ExprWithLet
| "(" ExprWithLet ")"
| Expr
; Eventually however, e.g. with a follow-up RFC, I would like to turn The reference has not been updated because we only make updates to it once a feature becomes stable. With all that said, I'm open to tweaks to the error message (it's optimized for suggesting that e.g. |
I would be happy with a different error message for stable compilers that continued to call |
Should be easy to implement by tweaking the HIR lowering code just a tiny bit. Will try to do that sometime during the week but no firm promises. :) |
...but if anyone wants to work-steal this from me then this would be a good first issue. You'll want to tweak |
There's precedent for different messages depending on whether the current compiler is stable or not and whether there's a feature flag enabled or not. I don't think all three cases are needed here and just gate on the feature being enabled. |
I'd go further to say that we should be doing what @estebank describes most of the time: unless a feature is enabled, and the old diagnostics were useful, don't spit out new "you tried to use this feature but it's unstable" diagnostics that aren't helpful. |
I'll take a stab at it. First time contributor, so I might not know all the hurtles, but I'll take a swing at it. |
@rustbot assign @RobbieMcKinstry |
@Centril I'm not sure if this is a good idea, because if let Some(x) = foo && !let Some(y) = bar {
// we can access x, but not y
} else {
// what about this scope???
} |
@Aloso It's probably best to discuss that once an RFC is made but let's not do it here. :) |
@rustbot claim |
I've got the change locally now with exactly what @Centril had mentioned in a previous message. The only thing I'm getting right now is that the compiler is highlighting the entire statement and not just the I'm looking for the method where I can get this. I'll put up a PR in a bit to show where I'm at along with some terminal output to demonstrate a bit better what I'm talking about if it doesn't make sense already. |
Opened #65893 |
Don't worry about the span, it is ok as it is in your pr. |
cc @Centril
Code first. This code:
on current stable Rust 1.38, gives this set of error messages:
The part that I'm most concerned about is:
Before eRFC "if- and while-let-chains, take 2" (rust-lang/rfcs#2497, #53667, #53668), this code USED to result in this error message:
The reason I know this is because we have the old error message in the book, in the section where we're trying to explain the difference between statements and expressions. The error message I'm seeing now is muddying the waters by saying "
let
expressions".Based on my reading of the eRFC, it's only supposed to change
if let
, but as kind of a side effectlet
is now sort-of an expression? The updates to the reference don't clear it up for me, as they only describeif let
, not plainlet
s.What I expected is that even though the eRFC has been accepted and implemented, plain
let y = 6
would still be considered a statement and the error message wouldn't talk about "let
expressions".If my expectation is valid, then the compiler error message is a bug. If my expectation is invalid, please let me know so that I can work on updating the book. Thanks!
This issue has been assigned to @jafern14 via this comment.
The text was updated successfully, but these errors were encountered: