Open
Description
Refutable pattern in local binding - E0005
Patterns used to bind names must be irrefutable, that is, they must guarantee that a name will be extracted in all cases.
- You can view the same on
compiler-explorer
I tried this code from E0005
:
#![allow(unused)]
fn main() {
let x = Some(1);
let Some(y) = x;
// error: refutable pattern in local binding: `None` not covered
}
- Also this -
godbolt
#![allow(unused)]
fn main() {
let x = Some(1);
match x {
Some(y) => {
// do something
},
None => {}
}
// or:
if let Some(y) = x {
// do something
}
}
I expected to see this happen:
- Give error like rustc i.e.,
error[E0005]: refutable pattern in local binding: `None` not covered
Instead, this happened:
- Give wrong message & error code
➜ gccrs-build gcc/crab1 ../mahad-testsuite/E0005.rs
../mahad-testsuite/E0005.rs:3:9: error: Cannot find path ‘Some’ in this scope [E0433]
3 | let x = Some(1);
| ^~~~
../mahad-testsuite/E0005.rs:4:5: error: Cannot find path ‘Some’ in this scope [E0433]
4 | let Some(y) = x;
| ^~~~
Meta
- What version of Rust GCC were you using, git sha 6c63150
- gccrs (Compiler-Explorer-Build-gcc-dba8bc5bf8247161b6eff4f738b6479382f770f2-binutils-2.40) 13.0.1 20230417 (experimental)
Fixing this issue will also help this #2301 to emit error codes similiar to rustc.