Skip to content

rustc should probably warn on anonymous, unused closure statement #74691

Closed
@rphmeier

Description

@rphmeier

Not quite sure how to name this issue, please change the title to something more accurate!

Recently ran into this issue:

fn main() {
    let b = false; // dangerous semi-colon
        || true;
        
    println!("{}", b);
}

The boolean statement was long, so I broke it out onto a new line. However, I accidentally added the annotated semi-colon. The || true line is interpreted as an anonymous closure statement (no let binding, not even a callable closure) as opposed to a boolean OR.

When executing this code, it yields false. Luckily, someone caught the issue in code review, but a compiler warning noting the unused closure would have been really helpful!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions