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

Incorrect warn(unused_assignments) when assigned valued is compared with reference, but not read for value #53637

Closed
chrivers opened this issue Aug 23, 2018 · 2 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@chrivers
Copy link

I found a spurious warn(unused_assignments) which I've condensed into the following small test case:

fn flip(bit: &mut bool)
{
    *bit = !*bit;
}
    
fn main() {
    let mut fullscreen = false;
    let mut old_fullscreen = fullscreen;
    flip(&mut fullscreen);
    if fullscreen != old_fullscreen {
        println!("flipped");
        old_fullscreen = fullscreen;
    }
}
$ rustc src/main2.rs
warning: value assigned to `old_fullscreen` is never read
  --> src/main2.rs:12:9
   |
12 |         old_fullscreen = fullscreen;
   |         ^^^^^^^^^^^^^^
   |
   = note: #[warn(unused_assignments)] on by default
$ rustc --version
rustc 1.30.0-nightly (33b923fd4 2018-08-18)

It complains that the value of old_fullscreen is never read, but surely it is, since I'm comparing to it. In the real program, this is part of a main loop for a graphical application, and the value is checked like this in each iteration.

I checked for duplicated, and this does not seem to be related to #49171, which is about the ergonomics of a real warning, whereas this warning, if I understand correctly, should not be produced at all.

@estebank estebank added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Aug 24, 2018
@ollie27
Copy link
Member

ollie27 commented Aug 26, 2018

The lint seems to be correct here. The line it's warning about is the assignment after the comparison which is unused. You might be better off posting the original code.

@Dylan-DPC-zz
Copy link

Closing this as it looks intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

4 participants