@@ -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
@@ -4857,3 +4871,20 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
4857
4871
}
4858
4872
}
4859
4873
}
4874
+
4875
+ fn fatally_break_rust ( sess : & Session ) {
4876
+ let handler = sess. diagnostic ( ) ;
4877
+ handler. span_bug_no_panic (
4878
+ MultiSpan :: new ( ) ,
4879
+ "It looks like you're trying to break rust; would you like some ICE?" ,
4880
+ ) ;
4881
+ handler. note_without_error ( "the compiler expectedly panicked. this is a feature." ) ;
4882
+ handler. note_without_error (
4883
+ "we would appreciate a joke overview: \
4884
+ https://github.com/rust-lang/rust/issues/43162#issuecomment-320764675"
4885
+ ) ;
4886
+ handler. note_without_error ( & format ! ( "rustc {} running on {}" ,
4887
+ option_env!( "CFG_VERSION" ) . unwrap_or( "unknown_version" ) ,
4888
+ :: session:: config:: host_triple( ) ,
4889
+ ) ) ;
4890
+ }
0 commit comments