-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Don't suggest adding let
in certain if
conditions
#97856
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// FIXME(compiler-errors): This really should suggest `let` on the RHS of the | ||
// `&&` operator, but that's kinda hard to do because of precedence. | ||
// Instead, for now we just make sure not to suggest `if let let`. | ||
fn a() { | ||
if let x = 1 && i = 2 {} | ||
//~^ ERROR cannot find value `i` in this scope | ||
//~| ERROR `let` expressions in this position are unstable | ||
//~| ERROR mismatched types | ||
//~| ERROR `let` expressions are not supported here | ||
} | ||
|
||
fn b() { | ||
if (i + j) = i {} | ||
//~^ ERROR cannot find value `i` in this scope | ||
//~| ERROR cannot find value `i` in this scope | ||
//~| ERROR cannot find value `j` in this scope | ||
} | ||
|
||
fn c() { | ||
if x[0] = 1 {} | ||
//~^ ERROR cannot find value `x` in this scope | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
error: `let` expressions are not supported here | ||
--> $DIR/bad-if-let-suggestion.rs:5:8 | ||
| | ||
LL | if let x = 1 && i = 2 {} | ||
| ^^^^^^^^^ | ||
| | ||
= note: only supported directly in conditions of `if` and `while` expressions | ||
|
||
error[E0425]: cannot find value `i` in this scope | ||
--> $DIR/bad-if-let-suggestion.rs:5:21 | ||
| | ||
LL | if let x = 1 && i = 2 {} | ||
| ^ not found in this scope | ||
|
||
error[E0425]: cannot find value `i` in this scope | ||
--> $DIR/bad-if-let-suggestion.rs:13:9 | ||
| | ||
LL | fn a() { | ||
| ------ similarly named function `a` defined here | ||
... | ||
LL | if (i + j) = i {} | ||
| ^ help: a function with a similar name exists: `a` | ||
|
||
error[E0425]: cannot find value `j` in this scope | ||
--> $DIR/bad-if-let-suggestion.rs:13:13 | ||
| | ||
LL | fn a() { | ||
| ------ similarly named function `a` defined here | ||
... | ||
LL | if (i + j) = i {} | ||
| ^ help: a function with a similar name exists: `a` | ||
|
||
error[E0425]: cannot find value `i` in this scope | ||
--> $DIR/bad-if-let-suggestion.rs:13:18 | ||
| | ||
LL | fn a() { | ||
| ------ similarly named function `a` defined here | ||
... | ||
LL | if (i + j) = i {} | ||
| ^ help: a function with a similar name exists: `a` | ||
|
||
error[E0425]: cannot find value `x` in this scope | ||
--> $DIR/bad-if-let-suggestion.rs:20:8 | ||
| | ||
LL | fn a() { | ||
| ------ similarly named function `a` defined here | ||
... | ||
LL | if x[0] = 1 {} | ||
| ^ help: a function with a similar name exists: `a` | ||
|
||
error[E0658]: `let` expressions in this position are unstable | ||
--> $DIR/bad-if-let-suggestion.rs:5:8 | ||
| | ||
LL | if let x = 1 && i = 2 {} | ||
| ^^^^^^^^^ | ||
| | ||
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information | ||
= help: add `#![feature(let_chains)]` to the crate attributes to enable | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/bad-if-let-suggestion.rs:5:8 | ||
| | ||
LL | if let x = 1 && i = 2 {} | ||
| ^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` | ||
Comment on lines
+51
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be nice if all the errors pointing at line 5 (these plus the ones highlighted above) ended up being only one. Particularly the " There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, the problem is that they all happen in different stages :( so it's really hard to suppress further ones There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, for sure. I wasn't suggesting doing it in this PR, only mentioning what follow up work that I'd like to get to at some point. |
||
|
||
error: aborting due to 8 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0425, E0658. | ||
For more information about an error, try `rustc --explain E0308`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error isn't as good as it could be :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i left a fixme