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

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

Open
liamnaddell opened this issue Aug 10, 2024 · 1 comment
Open

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

liamnaddell opened this issue Aug 10, 2024 · 1 comment

Comments

@liamnaddell
Copy link
Contributor

liamnaddell commented Aug 10, 2024

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: be1e78b

@liamnaddell
Copy link
Contributor Author

This was discovered in testing for #914

@liamnaddell liamnaddell changed the title Bogus "field is never read" warning Bogus "field is never read" warning with dynamic references Aug 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant