Closed
Description
Summary
Spamming return
statements at the end of a function lowers the function's cognitive complexity score, which should not happen.
Lint Name
cognitive_complexity
Reproducer
I tried this code:
// cognitive_complexity lint is triggered
#[clippy::cognitive_complexity = "1"]
fn foo() {
for _ in 0..10 {
println!("hello there");
}
}
// cognitive_complexity lint is NOT triggered
#[clippy::cognitive_complexity = "1"]
fn bar() {
for _ in 0..10 {
println!("hello there");
}
return;
return;
}
I expected to see this happen:
- Lint should be triggered for both
foo
andbar
.
Instead, this happened:
- Lint only triggered for
foo
.
Version
rustc 1.87.0-nightly (00f245915 2025-02-26)
binary: rustc
commit-hash: 00f245915b0c7839d42c26f9628220c4f1b93bf6
commit-date: 2025-02-26
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0