Closed
Description
The following code produces an incorrect dead code warning ("warning: variant is never constructed: Variant
"), when using the Self
keyword. When using the enumeration name (E
), there is no warning.
// rustc --edition 2018 --crate-type rlib warning.rs
enum E {
Variant { _unused: () }
}
impl E {
fn new() -> Self {
Self::Variant { _unused: () }
// E::Variant { _unused: () } // <-- warning vanishes
}
}
pub struct S(E);
impl S {
pub fn new() -> Self {
Self(E::new())
}
}
Tested versions:
rustc 1.41.0 (5e1a79984 2020-01-27)
rustc 1.42.0-nightly (212b2c7da 2020-01-30)
rustc 1.43.0-nightly (58b834344 2020-02-05)
This issue has been assigned to @matprec via this comment.