Open
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
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
compiler-errors commentedon Apr 19, 2023
Strange... Given:
The MIR we generate for either associated const is quite different...
🤔
ericmarkmartin commentedon Jun 26, 2023
I'd like to take a swing at this
ericmarkmartin commentedon Jun 29, 2023
@rustbot claim
ericmarkmartin commentedon Jun 29, 2023
@compiler-errors I looked at the thir generated for your program
and
FOO
andBAR
are already different.FOO
has kindAdt
whereasBAR
has kindCall
.Rollup merge of rust-lang#113217 - ericmarkmartin:lower-type-relative…
Rollup merge of rust-lang#113217 - ericmarkmartin:lower-type-relative…