@@ -3652,6 +3652,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
36523652 // inside a loop at all, which is caught by the
36533653 // loop-checking pass.
36543654 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+ }
36553669 }
36563670
36573671 // 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>,
48804894 }
48814895 }
48824896}
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