@@ -94,7 +94,7 @@ use rustc_hir::intravisit::{self, Visitor};
94
94
use rustc_hir:: { Expr , HirId , HirIdMap , HirIdSet } ;
95
95
use rustc_index:: vec:: IndexVec ;
96
96
use rustc_middle:: ty:: query:: Providers ;
97
- use rustc_middle:: ty:: { self , DefIdTree , RootVariableMinCaptureList , Ty , TyCtxt } ;
97
+ use rustc_middle:: ty:: { self , DefIdTree , RootVariableMinCaptureList , TyCtxt } ;
98
98
use rustc_session:: lint;
99
99
use rustc_span:: symbol:: { kw, sym, Symbol } ;
100
100
use rustc_span:: { BytePos , Span } ;
@@ -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
}
@@ -359,7 +359,7 @@ impl<'tcx> IrMaps<'tcx> {
359
359
let shorthand_field_ids = self . collect_shorthand_field_ids ( pat) ;
360
360
361
361
pat. each_binding ( |_, hir_id, _, ident| {
362
- self . add_live_node_for_node ( hir_id, VarDefNode ( ident. span , hir_id ) ) ;
362
+ self . add_live_node_for_node ( hir_id, VarDefNode ( ident. span ) ) ;
363
363
self . add_variable ( Local ( LocalInfo {
364
364
id : hir_id,
365
365
name : ident. name ,
@@ -373,7 +373,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
373
373
fn visit_local ( & mut self , local : & ' tcx hir:: Local < ' tcx > ) {
374
374
self . add_from_pat ( & local. pat ) ;
375
375
if local. els . is_some ( ) {
376
- self . add_live_node_for_node ( local. hir_id , ExprNode ( local. span , local . hir_id ) ) ;
376
+ self . add_live_node_for_node ( local. hir_id , ExprNode ( local. span ) ) ;
377
377
}
378
378
intravisit:: walk_local ( self , local) ;
379
379
}
@@ -408,14 +408,14 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
408
408
hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) => {
409
409
debug ! ( "expr {}: path that leads to {:?}" , expr. hir_id, path. res) ;
410
410
if let Res :: Local ( _var_hir_id) = path. res {
411
- self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr . hir_id ) ) ;
411
+ self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
412
412
}
413
413
intravisit:: walk_expr ( self , expr) ;
414
414
}
415
415
hir:: ExprKind :: Closure { .. } => {
416
416
// Interesting control flow (for loops can contain labeled
417
417
// breaks or continues)
418
- self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr . hir_id ) ) ;
418
+ self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
419
419
420
420
// Make a live_node for each mentioned variable, with the span
421
421
// being the location that the variable is used. This results
@@ -444,11 +444,11 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
444
444
| hir:: ExprKind :: Match ( ..)
445
445
| hir:: ExprKind :: Loop ( ..)
446
446
| hir:: ExprKind :: Yield ( ..) => {
447
- self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr . hir_id ) ) ;
447
+ self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
448
448
intravisit:: walk_expr ( self , expr) ;
449
449
}
450
450
hir:: ExprKind :: Binary ( op, ..) if op. node . is_lazy ( ) => {
451
- self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr . hir_id ) ) ;
451
+ self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
452
452
intravisit:: walk_expr ( self , expr) ;
453
453
}
454
454
@@ -1284,60 +1284,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
1284
1284
fn check_is_ty_uninhabited ( & mut self , expr : & Expr < ' _ > , succ : LiveNode ) -> LiveNode {
1285
1285
let ty = self . typeck_results . expr_ty ( expr) ;
1286
1286
let m = self . ir . tcx . parent_module ( expr. hir_id ) . to_def_id ( ) ;
1287
- if self . ir . tcx . is_ty_uninhabited_from ( m, ty, self . param_env ) {
1288
- match self . ir . lnks [ succ] {
1289
- LiveNodeKind :: ExprNode ( succ_span, succ_id) => {
1290
- self . warn_about_unreachable ( expr. span , ty, succ_span, succ_id, "expression" ) ;
1291
- }
1292
- LiveNodeKind :: VarDefNode ( succ_span, succ_id) => {
1293
- self . warn_about_unreachable ( expr. span , ty, succ_span, succ_id, "definition" ) ;
1294
- }
1295
- _ => { }
1296
- } ;
1297
- self . exit_ln
1298
- } else {
1299
- succ
1300
- }
1301
- }
1302
-
1303
- fn warn_about_unreachable (
1304
- & mut self ,
1305
- orig_span : Span ,
1306
- orig_ty : Ty < ' tcx > ,
1307
- expr_span : Span ,
1308
- expr_id : HirId ,
1309
- descr : & str ,
1310
- ) {
1311
- if !orig_ty. is_never ( ) {
1312
- // Unreachable code warnings are already emitted during type checking.
1313
- // However, during type checking, full type information is being
1314
- // calculated but not yet available, so the check for diverging
1315
- // expressions due to uninhabited result types is pretty crude and
1316
- // only checks whether ty.is_never(). Here, we have full type
1317
- // information available and can issue warnings for less obviously
1318
- // uninhabited types (e.g. empty enums). The check above is used so
1319
- // that we do not emit the same warning twice if the uninhabited type
1320
- // is indeed `!`.
1321
-
1322
- let msg = format ! ( "unreachable {}" , descr) ;
1323
- self . ir . tcx . struct_span_lint_hir (
1324
- lint:: builtin:: UNREACHABLE_CODE ,
1325
- expr_id,
1326
- expr_span,
1327
- & msg,
1328
- |diag| {
1329
- diag. span_label ( expr_span, & msg)
1330
- . span_label ( orig_span, "any code following this expression is unreachable" )
1331
- . span_note (
1332
- orig_span,
1333
- & format ! (
1334
- "this expression has type `{}`, which is uninhabited" ,
1335
- orig_ty
1336
- ) ,
1337
- )
1338
- } ,
1339
- ) ;
1340
- }
1287
+ if self . ir . tcx . is_ty_uninhabited_from ( m, ty, self . param_env ) { self . exit_ln } else { succ }
1341
1288
}
1342
1289
}
1343
1290
0 commit comments