@@ -7,7 +7,7 @@ use clippy_utils::source::snippet;
7
7
use clippy_utils:: visitors:: { Descend , for_each_expr_without_closures} ;
8
8
use rustc_errors:: Applicability ;
9
9
use 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 ,
11
11
} ;
12
12
use rustc_lint:: LateContext ;
13
13
use rustc_span:: { BytePos , Span , sym} ;
@@ -75,12 +75,19 @@ pub(super) fn check<'tcx>(
75
75
fn contains_any_break_or_continue ( block : & Block < ' _ > ) -> bool {
76
76
for_each_expr_without_closures ( block, |e| match e. kind {
77
77
ExprKind :: Break ( ..) | ExprKind :: Continue ( ..) => ControlFlow :: Break ( ( ) ) ,
78
+ ExprKind :: InlineAsm ( asm) if contains_label ( asm) => ControlFlow :: Break ( ( ) ) ,
78
79
ExprKind :: Loop ( ..) => ControlFlow :: Continue ( Descend :: No ) ,
79
80
_ => ControlFlow :: Continue ( Descend :: Yes ) ,
80
81
} )
81
82
. is_some ( )
82
83
}
83
84
85
+ fn contains_label ( asm : & InlineAsm < ' _ > ) -> bool {
86
+ asm. operands
87
+ . iter ( )
88
+ . any ( |( op, _span) | matches ! ( op, InlineAsmOperand :: Label { .. } ) )
89
+ }
90
+
84
91
/// The `never_loop` analysis keeps track of three things:
85
92
///
86
93
/// * Has any (reachable) code path hit a `continue` of the main loop?
@@ -378,7 +385,15 @@ fn never_loop_expr<'tcx>(
378
385
InlineAsmOperand :: Const { .. } | InlineAsmOperand :: SymFn { .. } | InlineAsmOperand :: SymStatic { .. } => {
379
386
NeverLoopResult :: Normal
380
387
} ,
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
+ } ,
382
397
} ) ) ,
383
398
ExprKind :: OffsetOf ( _, _)
384
399
| ExprKind :: Yield ( _, _)
0 commit comments