#17384·rust-clippy

Since 1.97 Clippy flags else return { None } under question_mark, even in longer chains

Author: orlpCreated Jul 9, 2026Updated Sep 17, 2026
LabelsC-bugI-false-positive

Description

Consider this minified example:

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

rust
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