@@ -2490,6 +2490,8 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
2490
2490
// of arguments when we typecheck the functions. This isn't really the
2491
2491
// right way to do this.
2492
2492
let xs = [ false , true ] ;
2493
+ let mut any_diverges = false ; // has any of the arguments diverged?
2494
+ let mut warned = false ; // have we already warned about unreachable code?
2493
2495
for check_blocks in & xs {
2494
2496
let check_blocks = * check_blocks;
2495
2497
debug ! ( "check_blocks={}" , check_blocks) ;
@@ -2512,6 +2514,16 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
2512
2514
supplied_arg_count
2513
2515
} ;
2514
2516
for ( i, arg) in args. iter ( ) . take ( t) . enumerate ( ) {
2517
+ if any_diverges && !warned {
2518
+ fcx. ccx
2519
+ . tcx
2520
+ . sess
2521
+ . add_lint ( lint:: builtin:: UNREACHABLE_CODE ,
2522
+ arg. id ,
2523
+ arg. span ,
2524
+ "unreachable expression" . to_string ( ) ) ;
2525
+ warned = true ;
2526
+ }
2515
2527
let is_block = match arg. node {
2516
2528
hir:: ExprClosure ( ..) => true ,
2517
2529
_ => false
@@ -2542,7 +2554,23 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
2542
2554
coerce_ty. map ( |ty| demand:: suptype ( fcx, arg. span , formal_ty, ty) ) ;
2543
2555
} ) ;
2544
2556
}
2557
+
2558
+ if let Some ( & arg_ty) = fcx. inh . tables . borrow ( ) . node_types . get ( & arg. id ) {
2559
+ any_diverges = any_diverges || fcx. infcx ( ) . type_var_diverges ( arg_ty) ;
2560
+ }
2561
+ }
2562
+ if any_diverges && !warned {
2563
+ let parent = fcx. ccx . tcx . map . get_parent_node ( args[ 0 ] . id ) ;
2564
+ fcx. ccx
2565
+ . tcx
2566
+ . sess
2567
+ . add_lint ( lint:: builtin:: UNREACHABLE_CODE ,
2568
+ parent,
2569
+ sp,
2570
+ "unreachable call" . to_string ( ) ) ;
2571
+ warned = true ;
2545
2572
}
2573
+
2546
2574
}
2547
2575
2548
2576
// We also need to make sure we at least write the ty of the other
0 commit comments