Skip to content

False dead_code warning on struct pattern match #56750

Open
@nvzqz

Description

@nvzqz

The following code will emit a dead_code warning (playground):

use std::mem;

fn main() {
    struct Value {
        a: i32,
        b: i32,
    };

    let Value { a, b } = unsafe { mem::zeroed() };
    println!("{} {}", a, b);
}

It states that Value is never constructed when in fact it has been within the let Value { a, b } pattern match.

   Compiling playground v0.0.1 (/playground)
warning: struct is never constructed: `Value`
 --> src/main.rs:4:5
  |
4 |     struct Value {
  |     ^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.90s
     Running `target/debug/playground`

Metadata

Metadata

Assignees

No one assigned

    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