Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jfrimmel opened this issue Feb 10, 2020 · 4 comments
Closed

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

jfrimmel opened this issue Feb 10, 2020 · 4 comments
Assignees
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jfrimmel
Copy link
Contributor

jfrimmel commented Feb 10, 2020

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.

@jonas-schievink jonas-schievink added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 10, 2020
@matprec
Copy link
Contributor

matprec commented Feb 10, 2020

@rustbot claim

@rustbot rustbot self-assigned this Feb 10, 2020
@Lonami
Copy link
Contributor

Lonami commented Feb 10, 2020

Possible duplicate of #64362.

@davidvartan
Copy link

Seeing this as well (warning occurs with Self::, does not occur when name of enum is used.)

@Lonami
Copy link
Contributor

Lonami commented Apr 24, 2020

Looks like #71026 fixed it, I can't reproduce the issue in the current Nightly or even Beta 1.44.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants