Skip to content

remove-unnecessary-else bad suggestions and false positives on thread_local macro #16556

Closed
@awused

Description

@awused

rust-analyzer version: rust-analyzer 0.3.1839-standalone

rustc version: rustc 1.76.0 (07dca489a 2024-02-04)

relevant settings: Unlikely any are relevant

Bad suggestions: Given this code

fn main() {
    let files = [1];

    let query = if files.is_empty() {
        return;
    } else if files.len() == 1 {
        1
    } else {
        17
    };
    print!("{query}");
}

remove-unnecessary-else suggests

fn main() {
    let files = [1];

    let query = if files.is_empty() {
        return;
    }
    if files.len() == 1 {
        1
    } else {
        17
    };
    print!("{query}");
}

which doesn't compile.

I also get false positives on thread_local!{} macros, but I don't have a minimal reproduction. In my projects it lints on every thread_local!{} call, even those as simple as thread_local!(static SOMETHING: Cell<u32> = Cell::default()); but I don't get the lints in minimal projects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsdiagnostics / error reportingBroken WindowBugs / technical debt to be addressed immediatelyC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions