Skip to content

Incorrect dead-code-warning on enum when using Self #69018

Closed
@jfrimmel

Description

@jfrimmel

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.

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-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