@@ -3652,6 +3652,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3652
3652
// inside a loop at all, which is caught by the
3653
3653
// loop-checking pass.
3654
3654
assert ! ( self . tcx. sess. err_count( ) > 0 ) ;
3655
+
3656
+ // We still need to assign a type to the inner expression to
3657
+ // prevent the ICE in #43162.
3658
+ if let Some ( ref e) = * expr_opt {
3659
+ self . check_expr_with_hint ( e, tcx. types . err ) ;
3660
+
3661
+ // ... except when we try to 'break rust;'.
3662
+ // ICE this expression in particular (see #43162).
3663
+ if let hir:: ExprPath ( hir:: QPath :: Resolved ( _, ref path) ) = e. node {
3664
+ if path. segments . len ( ) == 1 && path. segments [ 0 ] . name == "rust" {
3665
+ fatally_break_rust ( self . tcx . sess ) ;
3666
+ }
3667
+ }
3668
+ }
3655
3669
}
3656
3670
3657
3671
// the type of a `break` is always `!`, since it diverges
@@ -4880,3 +4894,20 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
4880
4894
}
4881
4895
}
4882
4896
}
4897
+
4898
+ fn fatally_break_rust ( sess : & Session ) {
4899
+ let handler = sess. diagnostic ( ) ;
4900
+ handler. span_bug_no_panic (
4901
+ MultiSpan :: new ( ) ,
4902
+ "It looks like you're trying to break rust; would you like some ICE?" ,
4903
+ ) ;
4904
+ handler. note_without_error ( "the compiler expectedly panicked. this is a feature." ) ;
4905
+ handler. note_without_error (
4906
+ "we would appreciate a joke overview: \
4907
+ https://github.com/rust-lang/rust/issues/43162#issuecomment-320764675"
4908
+ ) ;
4909
+ handler. note_without_error ( & format ! ( "rustc {} running on {}" ,
4910
+ option_env!( "CFG_VERSION" ) . unwrap_or( "unknown_version" ) ,
4911
+ :: session:: config:: host_triple( ) ,
4912
+ ) ) ;
4913
+ }
0 commit comments