Skip to content

[Rust] Unused variable false positive in compound conditional statements #20201

@tarolling

Description

@tarolling

Description of the false positive

When there is an if-let statement, and multiple conditions exist in the conditional check (either AND or OR as operators), CodeQL flags the original variable as unused if it is used in subsequent conditional statements.

Code samples or links to source code

There are many dismissed false positives linked to this merged PR: tarolling/seiri#57

A small example would be:

for result in builder.build() {
        match result {
            Ok(entry) => {
                if let Some(file_type) = entry.file_type()
                    && file_type.is_file()
                {
                    paths.push(entry.path().to_path_buf());
                }
            }
            Err(msg) => eprintln!("Error reading entry: {msg}"),
        }
    }

Here, file_type was flagged as a false positive, even though it is used in the following boolean statement file_type.is_file().

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions