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
{{ message }}
Repository navigation
very weird warning when using same varname for const and let binding #112269
This will cause rustc to interpret the y as a if let binding for some reason which seems quite surprising.
error[E0005]: refutable pattern in local binding
--> src/main.rs:3:9
|
3 | let y: i32 = 3;
| ^ patterns `i32::MIN..=3_i32` and `5_i32..=i32::MAX` not covered
|
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
= note: the matched value is of type `i32`
help: you might want to use `if let` to ignore the variants that aren't matched
|
3 | if let y: i32 = 3 { todo!() };
| ++ +++++++++++
For more information about this error, try `rustc --explain E0005`.
When I replace let by static, I get a warning that seems to be much closer to reality:
pubfnmain(){const y:i32 = 4;static y:i32 = 3;}
error[E0428]: the name `y` is defined multiple times
--> src/main.rs:3:5
|
2 | const y: i32 = 4;
| ----------------- previous definition of the value `y` here
3 | static y: i32 = 3;
| ^^^^^^^^^^^^^^^^^^ `y` redefined here
|
= note: `y` must be defined only once in the value namespace of this block
For more information about this error, try `rustc --explain E0428`.
error: could not compile `playground` (bin "playground") due to previous error
IMO it would make sense to issue such warning for the first case as well, instead of the if-let/range diagnostic.
Activity
Auto merge of rust-lang#112272 - jieyouxu:issue-112269, r=compiler-er…