- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.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
I'm sure that there is a more concise way to generate this error, but this produces a dead_code lint warning:
#![deny(warnings)]
use std::mem;
#[derive(Default)]
struct Y {}
enum X {
    A { y: Y },
    B { y: Y },
}
impl X {
    fn test(&mut self) {
        if let Self::A { y } = self {
            *self = Self::B { y: mem::take(y) };
        }
    }
}
pub fn main() {
    let mut x = X::A { y: Y {} };
    x.test();
}This code instantiates X::B, but the dead_code lint disagrees:
   Compiling playground v0.0.1 (/playground)
error: variant is never constructed: `B`
 --> src/main.rs:9:5
  |
9 |     B { y: Y },
  |     ^^^^^^^^^^
  |
note: lint level defined here
 --> src/main.rs:1:9
  |
1 | #![deny(warnings)]
  |         ^^^^^^^^
  = note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`
jmdejong
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.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.