@@ -94,7 +94,7 @@ use rustc_hir::intravisit::{self, Visitor};
9494use rustc_hir:: { Expr , HirId , HirIdMap , HirIdSet } ;
9595use rustc_index:: IndexVec ;
9696use rustc_middle:: query:: Providers ;
97- use rustc_middle:: ty:: { self , RootVariableMinCaptureList , Ty , TyCtxt } ;
97+ use rustc_middle:: ty:: { self , RootVariableMinCaptureList , TyCtxt } ;
9898use rustc_session:: lint;
9999use rustc_span:: symbol:: { kw, sym, Symbol } ;
100100use rustc_span:: { BytePos , Span } ;
@@ -118,8 +118,8 @@ rustc_index::newtype_index! {
118118#[ derive( Copy , Clone , PartialEq , Debug ) ]
119119enum LiveNodeKind {
120120 UpvarNode ( Span ) ,
121- ExprNode ( Span , HirId ) ,
122- VarDefNode ( Span , HirId ) ,
121+ ExprNode ( Span ) ,
122+ VarDefNode ( Span ) ,
123123 ClosureNode ,
124124 ExitNode ,
125125 ErrNode ,
@@ -129,8 +129,8 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String {
129129 let sm = tcx. sess . source_map ( ) ;
130130 match lnk {
131131 UpvarNode ( s) => format ! ( "Upvar node [{}]" , sm. span_to_diagnostic_string( s) ) ,
132- ExprNode ( s, _ ) => format ! ( "Expr node [{}]" , sm. span_to_diagnostic_string( s) ) ,
133- VarDefNode ( s, _ ) => format ! ( "Var def node [{}]" , sm. span_to_diagnostic_string( s) ) ,
132+ ExprNode ( s) => format ! ( "Expr node [{}]" , sm. span_to_diagnostic_string( s) ) ,
133+ VarDefNode ( s) => format ! ( "Var def node [{}]" , sm. span_to_diagnostic_string( s) ) ,
134134 ClosureNode => "Closure node" . to_owned ( ) ,
135135 ExitNode => "Exit node" . to_owned ( ) ,
136136 ErrNode => "Error node" . to_owned ( ) ,
@@ -331,7 +331,7 @@ impl<'tcx> IrMaps<'tcx> {
331331 let shorthand_field_ids = self . collect_shorthand_field_ids ( pat) ;
332332
333333 pat. each_binding ( |_, hir_id, _, ident| {
334- self . add_live_node_for_node ( hir_id, VarDefNode ( ident. span , hir_id ) ) ;
334+ self . add_live_node_for_node ( hir_id, VarDefNode ( ident. span ) ) ;
335335 self . add_variable ( Local ( LocalInfo {
336336 id : hir_id,
337337 name : ident. name ,
@@ -345,7 +345,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
345345 fn visit_local ( & mut self , local : & ' tcx hir:: LetStmt < ' tcx > ) {
346346 self . add_from_pat ( local. pat ) ;
347347 if local. els . is_some ( ) {
348- self . add_live_node_for_node ( local. hir_id , ExprNode ( local. span , local . hir_id ) ) ;
348+ self . add_live_node_for_node ( local. hir_id , ExprNode ( local. span ) ) ;
349349 }
350350 intravisit:: walk_local ( self , local) ;
351351 }
@@ -377,13 +377,13 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
377377 hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, path) ) => {
378378 debug ! ( "expr {}: path that leads to {:?}" , expr. hir_id, path. res) ;
379379 if let Res :: Local ( _var_hir_id) = path. res {
380- self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr . hir_id ) ) ;
380+ self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
381381 }
382382 }
383383 hir:: ExprKind :: Closure ( closure) => {
384384 // Interesting control flow (for loops can contain labeled
385385 // breaks or continues)
386- self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr . hir_id ) ) ;
386+ self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
387387
388388 // Make a live_node for each mentioned variable, with the span
389389 // being the location that the variable is used. This results
@@ -409,15 +409,15 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
409409 | hir:: ExprKind :: Match ( ..)
410410 | hir:: ExprKind :: Loop ( ..)
411411 | hir:: ExprKind :: Yield ( ..) => {
412- self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr . hir_id ) ) ;
412+ self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
413413 }
414414 hir:: ExprKind :: Binary ( op, ..) if op. node . is_lazy ( ) => {
415- self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr . hir_id ) ) ;
415+ self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
416416 }
417417
418418 // Inline assembly may contain labels.
419419 hir:: ExprKind :: InlineAsm ( asm) if asm. contains_label ( ) => {
420- self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr . hir_id ) ) ;
420+ self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
421421 intravisit:: walk_expr ( self , expr) ;
422422 }
423423
@@ -1297,52 +1297,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
12971297 fn check_is_ty_uninhabited ( & mut self , expr : & Expr < ' _ > , succ : LiveNode ) -> LiveNode {
12981298 let ty = self . typeck_results . expr_ty ( expr) ;
12991299 let m = self . ir . tcx . parent_module ( expr. hir_id ) . to_def_id ( ) ;
1300- if ty. is_inhabited_from ( self . ir . tcx , m, self . param_env ) {
1301- return succ;
1302- }
1303- match self . ir . lnks [ succ] {
1304- LiveNodeKind :: ExprNode ( succ_span, succ_id) => {
1305- self . warn_about_unreachable ( expr. span , ty, succ_span, succ_id, "expression" ) ;
1306- }
1307- LiveNodeKind :: VarDefNode ( succ_span, succ_id) => {
1308- self . warn_about_unreachable ( expr. span , ty, succ_span, succ_id, "definition" ) ;
1309- }
1310- _ => { }
1311- } ;
1312- self . exit_ln
1313- }
1314-
1315- fn warn_about_unreachable < ' desc > (
1316- & mut self ,
1317- orig_span : Span ,
1318- orig_ty : Ty < ' tcx > ,
1319- expr_span : Span ,
1320- expr_id : HirId ,
1321- descr : & ' desc str ,
1322- ) {
1323- if !orig_ty. is_never ( ) {
1324- // Unreachable code warnings are already emitted during type checking.
1325- // However, during type checking, full type information is being
1326- // calculated but not yet available, so the check for diverging
1327- // expressions due to uninhabited result types is pretty crude and
1328- // only checks whether ty.is_never(). Here, we have full type
1329- // information available and can issue warnings for less obviously
1330- // uninhabited types (e.g. empty enums). The check above is used so
1331- // that we do not emit the same warning twice if the uninhabited type
1332- // is indeed `!`.
1333-
1334- self . ir . tcx . emit_node_span_lint (
1335- lint:: builtin:: UNREACHABLE_CODE ,
1336- expr_id,
1337- expr_span,
1338- errors:: UnreachableDueToUninhabited {
1339- expr : expr_span,
1340- orig : orig_span,
1341- descr,
1342- ty : orig_ty,
1343- } ,
1344- ) ;
1345- }
1300+ if ty. is_inhabited_from ( self . ir . tcx , m, self . param_env ) { succ } else { self . exit_ln }
13461301 }
13471302}
13481303
0 commit comments