Skip to content

Commit 8f9607f

Browse files
committed
De-weirdify fatally_break_rust.
The easter egg ICE on `break rust` is weird: it's the one ICE in the entire compiler that doesn't immediately abort, which makes it annoyingly inconsistent. This commit changes it to abort. As part of this, the extra notes are now appended onto the bug dignostic, rather than being printed as individual note diagnostics, which changes the output format a bit. These changes don't interferes with the joke, but they do help with my ongoing cleanups to error handling.
1 parent 072c157 commit 8f9607f

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

compiler/rustc_hir_typeck/src/lib.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use crate::expectation::Expectation;
5252
use crate::fn_ctxt::RawTy;
5353
use crate::gather_locals::GatherLocalsVisitor;
5454
use rustc_data_structures::unord::UnordSet;
55-
use rustc_errors::{struct_span_err, DiagnosticId, ErrorGuaranteed, MultiSpan};
55+
use rustc_errors::{struct_span_err, DiagnosticId, ErrorGuaranteed};
5656
use rustc_hir as hir;
5757
use rustc_hir::def::{DefKind, Res};
5858
use rustc_hir::intravisit::Visitor;
@@ -412,24 +412,23 @@ enum TupleArgumentsFlag {
412412
TupleArguments,
413413
}
414414

415-
fn fatally_break_rust(tcx: TyCtxt<'_>) {
415+
fn fatally_break_rust(tcx: TyCtxt<'_>) -> ! {
416416
let dcx = tcx.sess.dcx();
417-
dcx.span_bug_no_panic(
418-
MultiSpan::new(),
419-
"It looks like you're trying to break rust; would you like some ICE?",
420-
);
421-
dcx.note("the compiler expectedly panicked. this is a feature.");
422-
dcx.note(
417+
let mut diag =
418+
dcx.struct_bug("It looks like you're trying to break rust; would you like some ICE?");
419+
diag.note("the compiler expectedly panicked. this is a feature.");
420+
diag.note(
423421
"we would appreciate a joke overview: \
424422
https://github.com/rust-lang/rust/issues/43162#issuecomment-320764675",
425423
);
426-
dcx.note(format!("rustc {} running on {}", tcx.sess.cfg_version, config::host_triple(),));
424+
diag.note(format!("rustc {} running on {}", tcx.sess.cfg_version, config::host_triple(),));
427425
if let Some((flags, excluded_cargo_defaults)) = rustc_session::utils::extra_compiler_flags() {
428-
dcx.note(format!("compiler flags: {}", flags.join(" ")));
426+
diag.note(format!("compiler flags: {}", flags.join(" ")));
429427
if excluded_cargo_defaults {
430-
dcx.note("some of the compiler flags provided by cargo are hidden");
428+
diag.note("some of the compiler flags provided by cargo are hidden");
431429
}
432430
}
431+
diag.emit()
433432
}
434433

435434
/// `expected` here is the expected number of explicit generic arguments on the trait.

tests/ui/track-diagnostics/track.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// compile-flags: -Z track-diagnostics
22
// error-pattern: created at
3+
// rustc-env:RUST_BACKTRACE=0
4+
// failure-status: 101
35

46
// Normalize the emitted location so this doesn't need
57
// updating everytime someone adds or removes a line.

tests/ui/track-diagnostics/track.stderr

+13-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,26 @@ LL | break rust
1313
-Ztrack-diagnostics: created at compiler/rustc_passes/src/loops.rs:LL:CC
1414

1515
error: internal compiler error: It looks like you're trying to break rust; would you like some ICE?
16+
|
17+
= note: the compiler expectedly panicked. this is a feature.
18+
= note: we would appreciate a joke overview: https://github.com/rust-lang/rust/issues/43162#issuecomment-320764675
19+
= note: rustc $VERSION running on $TARGET
20+
= note: compiler flags: ... -Z ui-testing ... -Z track-diagnostics
1621

17-
note: the compiler expectedly panicked. this is a feature.
22+
thread 'rustc' panicked at compiler/rustc_hir_typeck/src/lib.rs:LL:CC:
23+
Box<dyn Any>
24+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1825

19-
note: we would appreciate a joke overview: https://github.com/rust-lang/rust/issues/43162#issuecomment-320764675
26+
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
2027

2128
note: rustc $VERSION running on $TARGET
2229

2330
note: compiler flags: ... -Z ui-testing ... -Z track-diagnostics
2431

32+
query stack during panic:
33+
#0 [typeck] type-checking `main`
34+
#1 [analysis] running analysis passes on this crate
35+
end of query stack
2536
error: aborting due to 3 previous errors
2637

2738
Some errors have detailed explanations: E0268, E0425.

0 commit comments

Comments
 (0)