rust-lang / rust-lang/rust-clippy
Since 1.97 Clippy flags else return { None } under question_mark, even in longer chains
@profetia is already working on this.
Since Jul 16, 2026.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Description
Consider this minified example:
use std::any::Any;
fn dyn_str_as_int(p: &dyn Any) -> Option<u64> {
let s = if let Some(s) = p.downcast_ref::<&str>() {
s
} else if let Some(s) = p.downcast_ref::<String>() {
s.as_str()
} else {
return None;
};
s.parse().ok()
}
To me this reads naturally, there is a symmetry. Since 1.97 clippy however complains, saying it must be like this:
use std::any::Any;
fn dyn_str_as_int(p: &dyn Any) -> Option<u64> {
let s = if let Some(s) = p.downcast_ref::<&str>() {
s
} else {
let s = p.downcast_ref::<String>()?;
s.as_ref()
};
s.parse().ok()
}
I think (like collapsible_else_if) that this is at best a matter of taste, and definitely should not warn by default. My personal opinion is that this breaks symmetry, and that it makes refactoring more annoying (adding another else if branch means modifying this branch as well). I think in the past question_mark was a good hint, but now it has been poisoned.
I don't think the lint should trigger in if {} else if {} else if {} else { return None; } chains, or at the very least have this be toggleable, like collapsible_else_if is.
Version
rustc 1.97.0 (2d8144b78 2026-07-07)
binary: rustc
commit-hash: 2d8144b7880597b6e6d3dfd63a9a9efae3f533d3
commit-date: 2026-07-07
host: aarch64-apple-darwin
release: 1.97.0
LLVM version: 22.1.6
Additional Labels
No response
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.
Assessment
This issue has not been assessed yet.