@@ -95,7 +95,7 @@ use rustc_hir::intravisit::{self, Visitor};
95
95
use rustc_hir:: { Expr , HirId , HirIdMap , HirIdSet } ;
96
96
use rustc_index:: IndexVec ;
97
97
use rustc_middle:: query:: Providers ;
98
- use rustc_middle:: ty:: { self , RootVariableMinCaptureList , Ty , TyCtxt } ;
98
+ use rustc_middle:: ty:: { self , RootVariableMinCaptureList , TyCtxt } ;
99
99
use rustc_session:: lint;
100
100
use rustc_span:: symbol:: { kw, sym, Symbol } ;
101
101
use rustc_span:: DUMMY_SP ;
@@ -121,8 +121,8 @@ rustc_index::newtype_index! {
121
121
#[ derive( Copy , Clone , PartialEq , Debug ) ]
122
122
enum LiveNodeKind {
123
123
UpvarNode ( Span ) ,
124
- ExprNode ( Span , HirId ) ,
125
- VarDefNode ( Span , HirId ) ,
124
+ ExprNode ( Span ) ,
125
+ VarDefNode ( Span ) ,
126
126
ClosureNode ,
127
127
ExitNode ,
128
128
}
@@ -131,8 +131,8 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String {
131
131
let sm = tcx. sess . source_map ( ) ;
132
132
match lnk {
133
133
UpvarNode ( s) => format ! ( "Upvar node [{}]" , sm. span_to_diagnostic_string( s) ) ,
134
- ExprNode ( s, _ ) => format ! ( "Expr node [{}]" , sm. span_to_diagnostic_string( s) ) ,
135
- VarDefNode ( s, _ ) => format ! ( "Var def node [{}]" , sm. span_to_diagnostic_string( s) ) ,
134
+ ExprNode ( s) => format ! ( "Expr node [{}]" , sm. span_to_diagnostic_string( s) ) ,
135
+ VarDefNode ( s) => format ! ( "Var def node [{}]" , sm. span_to_diagnostic_string( s) ) ,
136
136
ClosureNode => "Closure node" . to_owned ( ) ,
137
137
ExitNode => "Exit node" . to_owned ( ) ,
138
138
}
@@ -354,7 +354,7 @@ impl<'tcx> IrMaps<'tcx> {
354
354
let shorthand_field_ids = self . collect_shorthand_field_ids ( pat) ;
355
355
356
356
pat. each_binding ( |_, hir_id, _, ident| {
357
- self . add_live_node_for_node ( hir_id, VarDefNode ( ident. span , hir_id ) ) ;
357
+ self . add_live_node_for_node ( hir_id, VarDefNode ( ident. span ) ) ;
358
358
self . add_variable ( Local ( LocalInfo {
359
359
id : hir_id,
360
360
name : ident. name ,
@@ -368,7 +368,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
368
368
fn visit_local ( & mut self , local : & ' tcx hir:: Local < ' tcx > ) {
369
369
self . add_from_pat ( & local. pat ) ;
370
370
if local. els . is_some ( ) {
371
- self . add_live_node_for_node ( local. hir_id , ExprNode ( local. span , local . hir_id ) ) ;
371
+ self . add_live_node_for_node ( local. hir_id , ExprNode ( local. span ) ) ;
372
372
}
373
373
intravisit:: walk_local ( self , local) ;
374
374
}
@@ -403,14 +403,14 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
403
403
hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) => {
404
404
debug ! ( "expr {}: path that leads to {:?}" , expr. hir_id, path. res) ;
405
405
if let Res :: Local ( _var_hir_id) = path. res {
406
- self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr . hir_id ) ) ;
406
+ self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
407
407
}
408
408
intravisit:: walk_expr ( self , expr) ;
409
409
}
410
410
hir:: ExprKind :: Closure ( closure) => {
411
411
// Interesting control flow (for loops can contain labeled
412
412
// breaks or continues)
413
- self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr . hir_id ) ) ;
413
+ self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
414
414
415
415
// Make a live_node for each mentioned variable, with the span
416
416
// being the location that the variable is used. This results
@@ -438,11 +438,11 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
438
438
| hir:: ExprKind :: Match ( ..)
439
439
| hir:: ExprKind :: Loop ( ..)
440
440
| hir:: ExprKind :: Yield ( ..) => {
441
- self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr . hir_id ) ) ;
441
+ self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
442
442
intravisit:: walk_expr ( self , expr) ;
443
443
}
444
444
hir:: ExprKind :: Binary ( op, ..) if op. node . is_lazy ( ) => {
445
- self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr . hir_id ) ) ;
445
+ self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
446
446
intravisit:: walk_expr ( self , expr) ;
447
447
}
448
448
@@ -1288,52 +1288,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
1288
1288
fn check_is_ty_uninhabited ( & mut self , expr : & Expr < ' _ > , succ : LiveNode ) -> LiveNode {
1289
1289
let ty = self . typeck_results . expr_ty ( expr) ;
1290
1290
let m = self . ir . tcx . parent_module ( expr. hir_id ) . to_def_id ( ) ;
1291
- if ty. is_inhabited_from ( self . ir . tcx , m, self . param_env ) {
1292
- return succ;
1293
- }
1294
- match self . ir . lnks [ succ] {
1295
- LiveNodeKind :: ExprNode ( succ_span, succ_id) => {
1296
- self . warn_about_unreachable ( expr. span , ty, succ_span, succ_id, "expression" ) ;
1297
- }
1298
- LiveNodeKind :: VarDefNode ( succ_span, succ_id) => {
1299
- self . warn_about_unreachable ( expr. span , ty, succ_span, succ_id, "definition" ) ;
1300
- }
1301
- _ => { }
1302
- } ;
1303
- self . exit_ln
1304
- }
1305
-
1306
- fn warn_about_unreachable < ' desc > (
1307
- & mut self ,
1308
- orig_span : Span ,
1309
- orig_ty : Ty < ' tcx > ,
1310
- expr_span : Span ,
1311
- expr_id : HirId ,
1312
- descr : & ' desc str ,
1313
- ) {
1314
- if !orig_ty. is_never ( ) {
1315
- // Unreachable code warnings are already emitted during type checking.
1316
- // However, during type checking, full type information is being
1317
- // calculated but not yet available, so the check for diverging
1318
- // expressions due to uninhabited result types is pretty crude and
1319
- // only checks whether ty.is_never(). Here, we have full type
1320
- // information available and can issue warnings for less obviously
1321
- // uninhabited types (e.g. empty enums). The check above is used so
1322
- // that we do not emit the same warning twice if the uninhabited type
1323
- // is indeed `!`.
1324
-
1325
- self . ir . tcx . emit_spanned_lint (
1326
- lint:: builtin:: UNREACHABLE_CODE ,
1327
- expr_id,
1328
- expr_span,
1329
- errors:: UnreachableDueToUninhabited {
1330
- expr : expr_span,
1331
- orig : orig_span,
1332
- descr,
1333
- ty : orig_ty,
1334
- } ,
1335
- ) ;
1336
- }
1291
+ if ty. is_inhabited_from ( self . ir . tcx , m, self . param_env ) { succ } else { self . exit_ln }
1337
1292
}
1338
1293
}
1339
1294
0 commit comments