Skip to content

Commit e9dffa3

Browse files
committed
Fix a bug in never_loop when anonymous blocks are nested in named blocks
The following code ``` loop { 'a: { { } break 'a; } } ``` was detected as a never-looping loop.
1 parent 1fec292 commit e9dffa3

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clippy_lints/src/loops/never_loop.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ fn never_loop_expr(expr: &Expr<'_>, ignore_ids: &mut Vec<HirId>, main_loop_id: H
163163
ignore_ids.push(b.hir_id);
164164
}
165165
let ret = never_loop_block(b, ignore_ids, main_loop_id);
166-
ignore_ids.pop();
166+
if l.is_some() {
167+
ignore_ids.pop();
168+
}
167169
ret
168170
},
169171
ExprKind::Continue(d) => {

tests/ui/never_loop.rs

+9
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ pub fn test20() {
250250
}
251251
}
252252

253+
pub fn test21() {
254+
loop {
255+
'a: {
256+
{ }
257+
break 'a;
258+
}
259+
}
260+
}
261+
253262
fn main() {
254263
test1();
255264
test2();

0 commit comments

Comments
 (0)