Skip to content

seemingly incorrect nontrivial_structural_match warning #110508

Open
@jmhain

Description

@jmhain

For the following code, I get a compiler warning:

#[derive(PartialEq, Eq)]
pub enum Thing { Foo(bool), Bar(Vec<()>) }

impl Thing {
    pub const FOO: Thing = Self::Foo(true);
}

pub fn foo(thing: Thing) {
    match thing {
        Thing::FOO => {},
        _ => {},
    }
}

Playground link

And the warning:

warning: to use a constant of type `Vec<()>` in a pattern, the constant's initializer must be trivial or `Vec<()>` must be annotated with `#[derive(PartialEq, Eq)]`
  --> src/lib.rs:10:9
   |
10 |         Thing::FOO => {},
   |         ^^^^^^^^^^
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, [see issue #73448 <https://github.com/rust-lang/rust/issues/73448>](https://github.com/rust-lang/rust/issues/73448)
   = note: `#[warn(nontrivial_structural_match)]` on by default

What makes me think this warning is incorrect is that the constant's initializer does not produce the Vec-containing variant like the warning suggests, and changing Self:: to Thing:: in the initializer resolves the error despite those (afaik) being equivalent.

Metadata

Metadata

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-patternsRelating to patterns and pattern matchingC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions