@@ -7,7 +7,7 @@ use clippy_utils::source::snippet;
77use clippy_utils:: visitors:: { Descend , for_each_expr_without_closures} ;
88use rustc_errors:: Applicability ;
99use rustc_hir:: {
10- Block , Destination , Expr , ExprKind , HirId , InlineAsmOperand , Node , Pat , Stmt , StmtKind , StructTailExpr ,
10+ Block , Destination , Expr , ExprKind , HirId , InlineAsm , InlineAsmOperand , Node , Pat , Stmt , StmtKind , StructTailExpr ,
1111} ;
1212use rustc_lint:: LateContext ;
1313use rustc_span:: { BytePos , Span , sym} ;
@@ -75,12 +75,19 @@ pub(super) fn check<'tcx>(
7575fn contains_any_break_or_continue ( block : & Block < ' _ > ) -> bool {
7676 for_each_expr_without_closures ( block, |e| match e. kind {
7777 ExprKind :: Break ( ..) | ExprKind :: Continue ( ..) => ControlFlow :: Break ( ( ) ) ,
78+ ExprKind :: InlineAsm ( asm) if contains_label ( asm) => ControlFlow :: Break ( ( ) ) ,
7879 ExprKind :: Loop ( ..) => ControlFlow :: Continue ( Descend :: No ) ,
7980 _ => ControlFlow :: Continue ( Descend :: Yes ) ,
8081 } )
8182 . is_some ( )
8283}
8384
85+ fn contains_label ( asm : & InlineAsm < ' _ > ) -> bool {
86+ asm. operands
87+ . iter ( )
88+ . any ( |( op, _span) | matches ! ( op, InlineAsmOperand :: Label { .. } ) )
89+ }
90+
8491/// The `never_loop` analysis keeps track of three things:
8592///
8693/// * Has any (reachable) code path hit a `continue` of the main loop?
@@ -378,7 +385,15 @@ fn never_loop_expr<'tcx>(
378385 InlineAsmOperand :: Const { .. } | InlineAsmOperand :: SymFn { .. } | InlineAsmOperand :: SymStatic { .. } => {
379386 NeverLoopResult :: Normal
380387 } ,
381- InlineAsmOperand :: Label { block } => never_loop_block ( cx, block, local_labels, main_loop_id) ,
388+ InlineAsmOperand :: Label { block } =>
389+ // We do not know whether the label will be executed or not, so `Diverging` must be
390+ // downgraded to `Normal`.
391+ {
392+ match never_loop_block ( cx, block, local_labels, main_loop_id) {
393+ NeverLoopResult :: Diverging { .. } => NeverLoopResult :: Normal ,
394+ result => result,
395+ }
396+ } ,
382397 } ) ) ,
383398 ExprKind :: OffsetOf ( _, _)
384399 | ExprKind :: Yield ( _, _)
0 commit comments