Skip to content

Wrong warning - "warning: value assigned to valid is never read" #43360

@yuval-k

Description

@yuval-k

i get this warning: warning: value assigned to `valid` is never read

This is the code:

fn main() {
    let mut valid = true;
    while valid {
        valid = false;
        println!("Bye!");
        continue;
    }
    println!("Hello, world!");
}

The warning is:

warning: value assigned to `valid` is never read
 --> src/main.rs:4:9
  |
4 |         valid = false;
  |         ^^^^^
  |
  = note: #[warn(unused_assignments)] on by default

value valid is said not to be read, but it is read as the while condition will be executed after the continue invocation.

tested via rust playground on stable, beta and nightly.
aside from the warning, the program behaves correctly

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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions