Rust-GCC / gccrs

GCC Front-End for Rust
https://rust-gcc.github.io/
GNU General Public License v2.0
2.39k stars 155 forks source link

Bogus "field is never read" warning with dynamic references #3127

Open liamnaddell opened 2 months ago

liamnaddell commented 2 months ago

I tried this code (which rustc compiles with no warnings)

struct Foo {
    my_int: u32,
}

trait Child {
    fn child(&self) -> u32;
}

impl Child for Foo {
    fn child(&self) -> u32 {
        return self.my_int;
    }
}

pub fn main() {
    let a = Foo{my_int: 0xfeedf00d};
    let b: &dyn Child = &a;

    b.child();

    // Here to silence bogus compiler warning
    //let _ = a.my_int;
}

What I get with rustc: Compiles with no warnings What I get with gccrs:

liam@gentoo ~/gccrs-build $ gccrs bogus_warning2.rs
bogus_warning2.rs:4:5: warning: field is never read: ‘my_int’
    4 |     my_int: u32,
      |     ^~~~~~

Discovered in: be1e78ba333435e2106227905bc63dfeb8718ff3

liamnaddell commented 2 months ago

This was discovered in testing for #914