github / github/codeql

[Rust] Unused variable false positive in compound conditional statements

Offen
#20,201 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
false-positive
Vorherrschende Sprache
CodeQL
Sterne
10.1k
Forks
2.1k
Ø Merge
2 T. 15 Std.
Gemergte PRs (30 T.)
141

Beschreibung

**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:

A small example would be:

```rust
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()`.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start by reproducing the Rust example and compare it with the dismissed false positives linked from seiri PR 57. Trace the CodeQL unused-variable analysis for if-let conditions with compound boolean operators; no source file or test is named in the issue. Done means the variable is no longer reported when used in a subsequent condition, with coverage for the shown case.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust
Bereich
security
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.