Skip to content

Commit a599527

Browse files
committed
Auto merge of #9837 - DesmondWillowbrook:never_loop, r=dswij
fix never_loop false positive fixes #9831 changelog: [`never_loop`]: fixed false positive on unconditional break in internal labeled block
2 parents 493b788 + 9899861 commit a599527

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clippy_lints/src/loops/never_loop.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
169169
combine_seq(e, arms)
170170
}
171171
},
172-
ExprKind::Block(b, _) => never_loop_block(b, main_loop_id),
172+
ExprKind::Block(b, None) => never_loop_block(b, main_loop_id),
173+
ExprKind::Block(b, Some(_label)) => absorb_break(never_loop_block(b, main_loop_id)),
173174
ExprKind::Continue(d) => {
174175
let id = d
175176
.target_id

tests/ui/never_loop.rs

+12
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ pub fn test18() {
229229
};
230230
}
231231

232+
// Issue #9831: unconditional break to internal labeled block
233+
pub fn test19() {
234+
fn thing(iter: impl Iterator) {
235+
for _ in iter {
236+
'b: {
237+
// error goes away if we just have the block's value be ().
238+
break 'b;
239+
}
240+
}
241+
}
242+
}
243+
232244
fn main() {
233245
test1();
234246
test2();

0 commit comments

Comments
 (0)