-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: 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, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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 => {},
_ => {},
}
}
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
Assignees
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: 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, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.