[never_loop]: recognize ? desugaring in try blocks

This commit is contained in:
y21 2024-01-27 17:07:10 +01:00
parent 66c29b973b
commit ff5afac616
2 changed files with 13 additions and 4 deletions

View File

@ -201,12 +201,12 @@ fn never_loop_expr<'tcx>(
})
})
},
ExprKind::Block(b, l) => {
if l.is_some() {
ExprKind::Block(b, _) => {
if b.targeted_by_break {
local_labels.push((b.hir_id, false));
}
let ret = never_loop_block(cx, b, local_labels, main_loop_id);
let jumped_to = l.is_some() && local_labels.pop().unwrap().1;
let jumped_to = b.targeted_by_break && local_labels.pop().unwrap().1;
match ret {
NeverLoopResult::Diverging if jumped_to => NeverLoopResult::Normal,
_ => ret,

View File

@ -1,4 +1,4 @@
#![feature(inline_const)]
#![feature(inline_const, try_blocks)]
#![allow(
clippy::eq_op,
clippy::single_match,
@ -400,6 +400,15 @@ pub fn test32() {
}
}
pub fn issue12205() -> Option<()> {
loop {
let _: Option<_> = try {
None?;
return Some(());
};
}
}
fn main() {
test1();
test2();