@@ -968,8 +968,7 @@ fn check_wild_err_arm<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm
968968 }
969969 if_chain ! {
970970 if matching_wild;
971- if let ExprKind :: Block ( block, _) = arm. body. kind;
972- if is_panic_block( block) ;
971+ if is_panic_call( arm. body) ;
973972 then {
974973 // `Err(_)` or `Err(_e)` arm with `panic!` found
975974 span_lint_and_note( cx,
@@ -1172,14 +1171,19 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
11721171}
11731172
11741173// If the block contains only a `panic!` macro (as expression or statement)
1175- fn is_panic_block ( block : & Block < ' _ > ) -> bool {
1176- match ( & block. expr , block. stmts . len ( ) , block. stmts . first ( ) ) {
1177- ( & Some ( exp) , 0 , _) => is_expn_of ( exp. span , "panic" ) . is_some ( ) && is_expn_of ( exp. span , "unreachable" ) . is_none ( ) ,
1178- ( & None , 1 , Some ( stmt) ) => {
1179- is_expn_of ( stmt. span , "panic" ) . is_some ( ) && is_expn_of ( stmt. span , "unreachable" ) . is_none ( )
1180- } ,
1181- _ => false ,
1182- }
1174+ fn is_panic_call ( expr : & Expr < ' _ > ) -> bool {
1175+ // Unwrap any wrapping blocks
1176+ let span = if let ExprKind :: Block ( block, _) = expr. kind {
1177+ match ( & block. expr , block. stmts . len ( ) , block. stmts . first ( ) ) {
1178+ ( & Some ( exp) , 0 , _) => exp. span ,
1179+ ( & None , 1 , Some ( stmt) ) => stmt. span ,
1180+ _ => return false ,
1181+ }
1182+ } else {
1183+ expr. span
1184+ } ;
1185+
1186+ is_expn_of ( span, "panic" ) . is_some ( ) && is_expn_of ( span, "unreachable" ) . is_none ( )
11831187}
11841188
11851189fn check_match_ref_pats < ' a , ' b , I > ( cx : & LateContext < ' _ > , ex : & Expr < ' _ > , pats : I , expr : & Expr < ' _ > )
0 commit comments