Skip to content

False warning "value assigned to a is never read" when read #45963

@gui1117

Description

@gui1117

in this example:

fn foo() -> Result<(), ()> {
    Ok(())
}

fn main() {
    let mut a = None;
    loop {
        let b = foo();
        if b.is_ok() {
            a = Some(b);
            break;
        }
    }
    println!("{:?}", a.unwrap().unwrap());
}

output: (on stable rustc 1.21.0 and nightly rustc 1.23.0-nightly)

   Compiling ressai v0.1.0 (file:///home/thiolliere/developpement/ressai)
warning: value assigned to `a` is never read
 --> main.rs:6:9
  |
6 |     let mut a = None;
  |         ^^^^^
  |
  = note: #[warn(unused_assignments)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.60 secs
     Running `/home/thiolliere/developpement/ressai/target/debug/ressai`
()

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