rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

non-exhaustive pattern false positive

Open avandecreme opened this issue 1 year ago โ€ข 5 comments

rust-analyzer version: v0.3.1916 (taken from the VSCode plugin page, the given command does nothing on my machine)

rustc version: 1.76.0 (07dca489a 2024-02-04)

editor or extension: VSCode with rust-analyzer v0.3.1916

relevant settings: NA

repository link (if public, optional): NA

code snippet to reproduce:

pub trait Foo {
    type Bar;
    fn foo(bar: Self::Bar);
}

pub struct FooImpl;

const foo_impl: () = {
    impl Foo for FooImpl {
        type Bar = ();

        fn foo(_bar: Self::Bar) {
            let () = _bar; // non-exhaustive pattern: `_` not covered reported here
        }
    }
};

This code compiles fine with rustc.

Any of the following changes make the error go away:

  1. Renaming _bar by bar
  2. Replacing fn foo(_bar: Self::Bar) by fn foo(_bar: ())
  3. Removing the const foo_impl: () = {...} wrapper

The original issue for me is when using proptest_derive, I get the error with this code:

#[derive(Arbitrary)]
pub enum Foo {
    Bar,
    Baz
}

The generated code looks similar to the repro above.

avandecreme avatar Apr 08 '24 09:04 avandecreme

I just started looking into this and got

image

---- handlers::non_exhaustive_let::tests::regression_issue_17031 stdout ----
thread 'handlers::non_exhaustive_let::tests::regression_issue_17031' panicked at crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs:393:21:
internal error: entered unreachable code: Unexpected type for `Struct` constructor: AssocTypeId(0)<[?0 := AdtId(StructId(StructId(0)))<[]>]>
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

interesting. Seems like a projection issue

ShoyuVanilla avatar Jun 22 '24 12:06 ShoyuVanilla

Does arbitrary still emit named const items?๐Ÿคจ They should really switch to const _ so we can support it properly

Veykril avatar Jun 25 '24 12:06 Veykril

It seems not have been so for 2 years ๐Ÿค”

https://github.com/rust-fuzz/arbitrary/blame/main/derive/src/lib.rs#L57

ShoyuVanilla avatar Jun 25 '24 12:06 ShoyuVanilla

My test case is generated by proptest_derive, not arbitrary.

Thanks for looking into it!

avandecreme avatar Jun 25 '24 12:06 avandecreme

proptest has been fixed recently ๐Ÿ‘ https://github.com/proptest-rs/proptest/commit/b1be99d2c3225325ef08072ef5f23f231e75a5fa#diff-1e85e98bbdbda751a72c78db697f0e85029d9600354a12d075e081a284f68816L121 Anyway, I'll try fixing the cases like in the example code of this issue

ShoyuVanilla avatar Jun 25 '24 12:06 ShoyuVanilla

Not sure if something changed recently but I'm getting thread 'Worker' panicked at crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs:401:21:\ninternal error: entered unreachable code: Unexpected type for Struct constructor: AssocTypeId(8088) very consistently immediately after opening certain files.

It also seems to happen if I pause while typing a for (a, b statement. Will try to reproduce.

ibraheemdev avatar Jul 30 '24 19:07 ibraheemdev

I see the same error above these days too:

thread 'Worker' panicked at crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs:407:21:
internal error: entered unreachable code: Unexpected type for `Struct` constructor: AssocTypeId(5805)<[?0 := 1<[?0 := AssocTypeId(5702)<[?0 := AdtId(StructId(StructId(8412)))<[]>]>]>]>

After this error occurred, I have to reload vscode.

edwin0cheng avatar Nov 17 '24 13:11 edwin0cheng

I see the same error above these days too:

thread 'Worker' panicked at crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs:407:21: internal error: entered unreachable code: Unexpected type for Struct constructor: AssocTypeId(5805)<[?0 := 1<[?0 := AssocTypeId(5702)<[?0 := AdtId(StructId(StructId(8412)))<[]>]>]>]>

After this error occurred, I have to reload vscode.

I think that this occurs when opening certain file. Could you let me know which file or project triggers this if you're working on a public codebase?

ShoyuVanilla avatar Nov 18 '24 02:11 ShoyuVanilla

I think that this occurs when opening certain file. Could you let me know which file or project triggers this if you're working on a public codebase?

Sorry, it is a private codebase and I am quite busy to find a MRE now. I just wanted to leave a comment here to show that this bug still occurs. :)

edwin0cheng avatar Nov 18 '24 02:11 edwin0cheng

Sorry, it is a private codebase and I am quite busy to find a MRE now. I just wanted to leave a comment here to show that this bug still occurs. :)

No worries. At least the error message you wrote gives some information ๐Ÿ˜„

ShoyuVanilla avatar Nov 18 '24 04:11 ShoyuVanilla