rust-lang / rust-lang/rust-clippy
False negatives on manual_map (regressions since 1.86)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
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 https://github.com/rust-lang/rust-clippy/pull/14389 would match the timeline of a change made between 14 February, 2025 and 28 March, 2025.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the manual_map lint implementation and compare the behavior associated with rust-lang/rust-clippy#14389. Run the supplied reproducer against the referenced compiler versions and verify that the relevant cases, including annotations and references, produce the expected warnings with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100