Skip to content

False negatives on manual_map (regressions since 1.86) #16031

@cmbartschat

Description

@cmbartschat

Summary

Including references in the result value, and the presence of type annotations on the assignment both seem to have an effect on the detection.

Lint Name

manual_map

Reproducer

I tried this code:

#![allow(dead_code, unused)] static TRUE: bool = true; static FALSE: bool = false; static STRINGS: [&str; 2] = ["hello", "hi"]; pub fn clippy_repo_auto_types(i: usize) { let trimmed = if let Some(v) = STRINGS.get(i) { Some(v.trim()) } else { None }; let len = if let Some(v) = STRINGS.get(i) { Some(v.len()) } else { None }; let is_long = if let Some(v) = STRINGS.get(i) { Some(if v.len() > 3 { &TRUE } else { &FALSE }) } else { None }; } pub fn clippy_repro_explicit_types(i: usize) { let trimmed: Option<&'static str> = if let Some(v) = STRINGS.get(i) { Some(v.trim()) } else { None }; let len: Option<usize> = if let Some(v) = STRINGS.get(i) { Some(v.len()) } else { None }; let is_long: Option<&'static bool> = if let Some(v) = STRINGS.get(i) { Some(if v.len() > 3 { &TRUE } else { &FALSE }) } else { None }; } pub fn clippy_repro_trim(i: usize) -> Option<&'static str> { if let Some(v) = STRINGS.get(i) { Some(v.trim()) } else { None } } pub fn clippy_repro_bool(i: usize) -> Option<&'static bool> { if let Some(v) = STRINGS.get(i) { Some(if v.len() > 3 { &TRUE } else { &FALSE }) } else { None } }

There are 8 occurrences which I believe break the manual_map rule.

On 1.90, we see 3 warnings: https://godbolt.org/z/KqTf7Gqjc

Going back to 1.86, there were 6 warnings: https://godbolt.org/z/nEx57EeoE

Seems like #14389 would match the timeline of a change made between 14 February, 2025 and 28 March, 2025.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions