Skip to content

non-exhaustive pattern false positive #17031

Open
@avandecreme

Description

@avandecreme

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-patternpattern handling related thingsC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions