Skip to content

False positive "field is never read" warnings #81626

Closed
@emilio

Description

@emilio

Here's a reduced test-case from Firefox source code:

struct Data {
    pub field: bool,
}

struct Foo<'a> {
    data: &'a mut Data,
}

impl<'a> Foo<'a> {
    fn parse_data(&mut self) {
        macro_rules! parse {
            () => {
                self.data.field = true;
            }
        }
        parse!()
    }
}

fn main() {
    let mut data = Data { field: false };
    {
        let mut foo = Foo { data: &mut data };
        foo.parse_data();
    }
    println!("{}", data.field);
}

Compiling that program warns with:

warning: field is never read: `data`
 --> t.rs:6:5
  |
6 |     data: &'a mut Data,
  |     ^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

Which is obviously not true.

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (04caa632d 2021-01-30)
binary: rustc
commit-hash: 04caa632dd10c2bf64b69524c7f9c4c30a436877
commit-date: 2021-01-30
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly
LLVM version: 11.0.1

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions