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

missing unreachable pattern [E0001] warning #2511

Open
MahadMuhammad opened this issue Aug 3, 2023 · 2 comments
Open

missing unreachable pattern [E0001] warning #2511

MahadMuhammad opened this issue Aug 3, 2023 · 2 comments
Labels
diagnostic diagnostic static analysis enhancement

Comments

@MahadMuhammad
Copy link
Contributor

MahadMuhammad commented Aug 3, 2023

E0001 unreachable pattern

  • Note: This error code is not longer emitted by rustc.
  • You can view the same on godbolt

I tried this code from E0001

#![allow(unused)]
fn main() {
match Some(0) {
    Some(bar) => {/* ... */}
    x => {/* ... */} // This handles the `None` case
    _ => {/* ... */} // All possible cases have already been handled
}
}

I expected to see this happen:

  • Compile successfully like rustc.

Instead, this happened:

  • Give error
➜  gccrs-build gcc/crab1 ../mahad-testsuite/E0001.rs
../mahad-testsuite/E0001.rs:3:7: error: Cannot find path ‘Some’ in this scope [E0433]
    3 | match Some(0) {
      |       ^~~~
../mahad-testsuite/E0001.rs:4:5: error: Cannot find path ‘Some’ in this scope [E0433]
    4 |     Some(bar) => {/* ... */}
      |     ^~~~

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)
@CohenArthur
Copy link
Member

This error is no longer emitted by rustc, and isn't emitted by rustc 1.49, so I don't think we should emit the error. We can compile this correctly, if we use an enum defined in the current crate instead of core:

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

fn main() {
    match AnEnum::VariantA(15) {
        AnEnum::VariantA(x) => {},
        rest => {},
        _ => {},
    }
}

however, we are missing the warnings that rustc emits regarding the unreachable pattern, so I'll update the title of this issue

@CohenArthur CohenArthur added enhancement diagnostic diagnostic static analysis and removed bug labels Aug 3, 2023
@CohenArthur CohenArthur changed the title unreachable pattern [E0001] missing unreachable pattern [E0001] warning Aug 3, 2023
@MahadMuhammad
Copy link
Contributor Author

MahadMuhammad commented Aug 3, 2023

Sure, thing @CohenArthur. I'll remember this from now :)

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

No branches or pull requests

2 participants