Skip to content
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

refutable pattern in local binding - [E0005] #2508

Open
MahadMuhammad opened this issue Aug 3, 2023 · 1 comment
Open

refutable pattern in local binding - [E0005] #2508

MahadMuhammad opened this issue Aug 3, 2023 · 1 comment
Labels

Comments

@MahadMuhammad
Copy link
Contributor

MahadMuhammad commented Aug 3, 2023

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.


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
}
#![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 ‘Somein this scope [E0433]
    3 | let x = Some(1);
      |         ^~~~
../mahad-testsuite/E0005.rs:4:5: error: Cannot find path ‘Somein 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.

@CohenArthur
Copy link
Member

The error you got is due to the standard prelude not being included by gccrs, as we cannot yet compile Rust's core library (which defines the Option type and its two None and Some variants). Here is a testcase which does not depend on core:

enum AnEnum {
    VariantA(i32),
    VariantB(f32),
}

fn main() {
    let x = AnEnum::VariantA(15);
    let AnEnum::VariantA(x_inner) = x;
}

which errors out with

arthur@platypus ~/G/r/gccrs (nr2.0-early-name-resolver) [1]> build/gcc/crab1 test.rs
test.rs:8:9: sorry, unimplemented: tuple-struct pattern let statements not supported
    8 |     let AnEnum::VariantA(x_inner) = x;
      |         ^~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants