@@ -1300,25 +1300,37 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
13001300 // that we do not emit the same warning twice if the uninhabited type
13011301 // is indeed `!`.
13021302
1303- self . ir . tcx . struct_span_lint_hir (
1304- lint:: builtin:: UNREACHABLE_CODE ,
1305- expr_id,
1306- expr_span,
1307- |lint| {
1308- let msg = format ! ( "unreachable {}" , descr) ;
1309- lint. build ( & msg)
1310- . span_label ( expr_span, & msg)
1311- . span_label ( orig_span, "any code following this expression is unreachable" )
1312- . span_note (
1313- orig_span,
1314- & format ! (
1315- "this expression has type `{}`, which is uninhabited" ,
1316- orig_ty
1317- ) ,
1318- )
1319- . emit ( ) ;
1320- } ,
1321- ) ;
1303+ if let Some ( hir:: Node :: Expr ( hir:: Expr {
1304+ kind : hir:: ExprKind :: Match ( _, [ ] , _) , ..
1305+ } ) ) = self . ir . tcx . hir ( ) . find ( expr_id)
1306+ {
1307+ // The expression we are about to lint on is an empty match, which
1308+ // can be used as a kind of "uninhabitedness assertion" (issue
1309+ // #89779). We do not want to lint in this case.
1310+ } else {
1311+ self . ir . tcx . struct_span_lint_hir (
1312+ lint:: builtin:: UNREACHABLE_CODE ,
1313+ expr_id,
1314+ expr_span,
1315+ |lint| {
1316+ let msg = format ! ( "unreachable {}" , descr) ;
1317+ lint. build ( & msg)
1318+ . span_label ( expr_span, & msg)
1319+ . span_label (
1320+ orig_span,
1321+ "any code following this expression is unreachable" ,
1322+ )
1323+ . span_note (
1324+ orig_span,
1325+ & format ! (
1326+ "this expression has type `{}`, which is uninhabited" ,
1327+ orig_ty
1328+ ) ,
1329+ )
1330+ . emit ( ) ;
1331+ } ,
1332+ ) ;
1333+ }
13221334 }
13231335 }
13241336}
0 commit comments