Fix LimitStack::pop_atr in release builds (#16371)

in `LimitStack::pop_atr` always call `stack.pop()`.
It used to only be called inside a `debug_assert!` so the stack was not
popped in release builds.

Running `TESTNAME=cognitive_complexity cargo uitest --release` used to
print
```
error: there was 1 unmatched diagnostic
   --> tests/ui/cognitive_complexity.rs:121:4
    |
121 | fn bloo() {
    |    ^^^^ Error[clippy::cognitive_complexity]: the function has a cognitive complexity
 of (2/1)
    |
```

The first commit adds to the ui test, which also fails in release, the
2nd commit fixes the tests.

changelog: [`cognitive_complexity`]: fix attribute stack not popping in
release builds
This commit is contained in:
llogiq 2026-01-09 20:14:30 +00:00 committed by GitHub
commit 11fe0c69b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 46 additions and 2 deletions

View file

@ -159,7 +159,10 @@ impl LimitStack {
}
pub fn pop_attrs(&mut self, sess: &Session, attrs: &[impl AttributeExt], name: Symbol) {
let stack = &mut self.stack;
parse_attrs(sess, attrs, name, |val| debug_assert_eq!(stack.pop(), Some(val)));
parse_attrs(sess, attrs, name, |val| {
let popped = stack.pop();
debug_assert_eq!(popped, Some(val));
});
}
}

View file

@ -472,3 +472,28 @@ mod issue14422 {
return;
}
}
#[clippy::cognitive_complexity = "1"]
mod attribute_stacking {
fn bad() {
//~^ cognitive_complexity
if true {
println!("a");
}
}
#[clippy::cognitive_complexity = "2"]
fn ok() {
if true {
println!("a");
}
}
// should revert to cognitive_complexity = "1"
fn bad_again() {
//~^ cognitive_complexity
if true {
println!("a");
}
}
}

View file

@ -176,5 +176,21 @@ LL | fn bar() {
|
= help: you could split it up into multiple smaller functions
error: aborting due to 22 previous errors
error: the function has a cognitive complexity of (2/1)
--> tests/ui/cognitive_complexity.rs:478:8
|
LL | fn bad() {
| ^^^
|
= help: you could split it up into multiple smaller functions
error: the function has a cognitive complexity of (2/1)
--> tests/ui/cognitive_complexity.rs:493:8
|
LL | fn bad_again() {
| ^^^^^^^^^
|
= help: you could split it up into multiple smaller functions
error: aborting due to 24 previous errors