You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnmain(){let value = Some(1);ifSome(x) = value {println!("yes");}else{println!("no");}}
and the compiler said:
error[E0425]: cannot find value `x` in this scope
--> src\main.rs:3:13
|
3 | if Some(x) = value {
| ^ not found in this scope
error[E0308]: mismatched types
--> src\main.rs:3:8
|
3 | if Some(x) = value {
| ^^^^^^^^^^^^^^^
| |
| expected `bool`, found `()`
| help: try comparing for equality: `Some(x) == value`
it suggested to change the = to ==, so I did, which fixed the second error but still caused:
error[E0425]: cannot find value `x` in this scope
--> src\main.rs:3:13
|
3 | if Some(x) == value {
| ^ not found in this scope
Instead, the help should suggest to add let in front of Some(x), which will fix the issue.
I understand it's not trivial for the compiler to know which will solve the issue, but at least checking if x exists in this scope to suggest the let solution will probably help a lot of people starting out with rust.
Thank you for the report! I agree that this should be fixed, but it is a duplicate of my oldest still open ticket: #44990 🙂. As you already mention it is not that easy to detect and will require us to jump through some hoops to fix it, but we will (eventually).
I tried to compile this code:
and the compiler said:
it suggested to change the
=
to==
, so I did, which fixed the second error but still caused:Instead, the help should suggest to add
let
in front ofSome(x)
, which will fix the issue.I understand it's not trivial for the compiler to know which will solve the issue, but at least checking if
x
exists in this scope to suggest thelet
solution will probably help a lot of people starting out with rust.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: