Skip to content

False warning: "unused logical operation that must be used" #69466

Open
@spacekookie

Description

@spacekookie

In a loop, in some cases, rustc seems to not understand that a boolean expression was used for sideeffects, and warns about unused logical operation. The following code can quickly replicate the problem.

use std::sync::{atomic::{AtomicBool, Ordering}, Arc};


fn main() {
    let running = Arc::new(AtomicBool::from(true));
    
    {
        let running = Arc::clone(&running);
        std::thread::spawn(move || {
            running.swap(false, Ordering::Relaxed);
        });
    }
    
    loop {
        // ...
        println!("Running....");
        
        !running.load(Ordering::Relaxed) && break;
    }
    
    println!("Exhausted >.>");
}

The expected result is that rustc doesn't output a warning in this case.

Meta

  • rustc version: 1.41.0

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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions