@@ -2490,6 +2490,8 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
24902490 // of arguments when we typecheck the functions. This isn't really the
24912491 // right way to do this.
24922492 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?
24932495 for check_blocks in & xs {
24942496 let check_blocks = * check_blocks;
24952497 debug ! ( "check_blocks={}" , check_blocks) ;
@@ -2512,6 +2514,16 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
25122514 supplied_arg_count
25132515 } ;
25142516 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+ }
25152527 let is_block = match arg. node {
25162528 hir:: ExprClosure ( ..) => true ,
25172529 _ => false
@@ -2542,7 +2554,23 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
25422554 coerce_ty. map ( |ty| demand:: suptype ( fcx, arg. span , formal_ty, ty) ) ;
25432555 } ) ;
25442556 }
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 ;
25452572 }
2573+
25462574 }
25472575
25482576 // We also need to make sure we at least write the ty of the other
0 commit comments