Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ff5afac

Browse files
committedJan 27, 2024
[never_loop]: recognize ? desugaring in try blocks
1 parent 66c29b9 commit ff5afac

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed
 

Diff for: ‎clippy_lints/src/loops/never_loop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ fn never_loop_expr<'tcx>(
201201
})
202202
})
203203
},
204-
ExprKind::Block(b, l) => {
205-
if l.is_some() {
204+
ExprKind::Block(b, _) => {
205+
if b.targeted_by_break {
206206
local_labels.push((b.hir_id, false));
207207
}
208208
let ret = never_loop_block(cx, b, local_labels, main_loop_id);
209-
let jumped_to = l.is_some() && local_labels.pop().unwrap().1;
209+
let jumped_to = b.targeted_by_break && local_labels.pop().unwrap().1;
210210
match ret {
211211
NeverLoopResult::Diverging if jumped_to => NeverLoopResult::Normal,
212212
_ => ret,

Diff for: ‎tests/ui/never_loop.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(inline_const)]
1+
#![feature(inline_const, try_blocks)]
22
#![allow(
33
clippy::eq_op,
44
clippy::single_match,
@@ -400,6 +400,15 @@ pub fn test32() {
400400
}
401401
}
402402

403+
pub fn issue12205() -> Option<()> {
404+
loop {
405+
let _: Option<_> = try {
406+
None?;
407+
return Some(());
408+
};
409+
}
410+
}
411+
403412
fn main() {
404413
test1();
405414
test2();

0 commit comments

Comments
 (0)
Failed to load comments.