@@ -94,7 +94,7 @@ use rustc_hir::intravisit::{self, Visitor};
94
94
use rustc_hir:: { Expr , HirId , HirIdMap , HirIdSet } ;
95
95
use rustc_index:: IndexVec ;
96
96
use rustc_middle:: query:: Providers ;
97
- use rustc_middle:: ty:: { self , RootVariableMinCaptureList , Ty , TyCtxt } ;
97
+ use rustc_middle:: ty:: { self , RootVariableMinCaptureList , TyCtxt } ;
98
98
use rustc_session:: lint;
99
99
use rustc_span:: symbol:: { kw, sym, Symbol } ;
100
100
use rustc_span:: { BytePos , Span } ;
@@ -118,8 +118,8 @@ rustc_index::newtype_index! {
118
118
#[ derive( Copy , Clone , PartialEq , Debug ) ]
119
119
enum LiveNodeKind {
120
120
UpvarNode ( Span ) ,
121
- ExprNode ( Span , HirId ) ,
122
- VarDefNode ( Span , HirId ) ,
121
+ ExprNode ( Span ) ,
122
+ VarDefNode ( Span ) ,
123
123
ClosureNode ,
124
124
ExitNode ,
125
125
ErrNode ,
@@ -129,8 +129,8 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String {
129
129
let sm = tcx. sess . source_map ( ) ;
130
130
match lnk {
131
131
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) ) ,
134
134
ClosureNode => "Closure node" . to_owned ( ) ,
135
135
ExitNode => "Exit node" . to_owned ( ) ,
136
136
ErrNode => "Error node" . to_owned ( ) ,
@@ -331,7 +331,7 @@ impl<'tcx> IrMaps<'tcx> {
331
331
let shorthand_field_ids = self . collect_shorthand_field_ids ( pat) ;
332
332
333
333
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 ) ) ;
335
335
self . add_variable ( Local ( LocalInfo {
336
336
id : hir_id,
337
337
name : ident. name ,
@@ -345,7 +345,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
345
345
fn visit_local ( & mut self , local : & ' tcx hir:: LetStmt < ' tcx > ) {
346
346
self . add_from_pat ( local. pat ) ;
347
347
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 ) ) ;
349
349
}
350
350
intravisit:: walk_local ( self , local) ;
351
351
}
@@ -377,13 +377,13 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
377
377
hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, path) ) => {
378
378
debug ! ( "expr {}: path that leads to {:?}" , expr. hir_id, path. res) ;
379
379
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 ) ) ;
381
381
}
382
382
}
383
383
hir:: ExprKind :: Closure ( closure) => {
384
384
// Interesting control flow (for loops can contain labeled
385
385
// 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 ) ) ;
387
387
388
388
// Make a live_node for each mentioned variable, with the span
389
389
// being the location that the variable is used. This results
@@ -409,15 +409,15 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
409
409
| hir:: ExprKind :: Match ( ..)
410
410
| hir:: ExprKind :: Loop ( ..)
411
411
| 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 ) ) ;
413
413
}
414
414
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 ) ) ;
416
416
}
417
417
418
418
// Inline assembly may contain labels.
419
419
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 ) ) ;
421
421
intravisit:: walk_expr ( self , expr) ;
422
422
}
423
423
@@ -1297,52 +1297,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
1297
1297
fn check_is_ty_uninhabited ( & mut self , expr : & Expr < ' _ > , succ : LiveNode ) -> LiveNode {
1298
1298
let ty = self . typeck_results . expr_ty ( expr) ;
1299
1299
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 }
1346
1301
}
1347
1302
}
1348
1303
0 commit comments