Skip to content

Commit 7e122e6

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 792a2e3 commit 7e122e6

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

compiler/rustc_hir_typeck/src/lib.rs

+10-13
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, Diagnostic, DiagnosticId, ErrorGuaranteed, Level};
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,26 +412,23 @@ enum TupleArgumentsFlag {
412412
TupleArguments,
413413
}
414414

415-
fn fatally_break_rust(tcx: TyCtxt<'_>) {
415+
fn fatally_break_rust(tcx: TyCtxt<'_>) -> ! {
416416
let handler = tcx.sess.diagnostic();
417-
// We normally use `handler.bug()` for bugs, but this is an exceptional case, so we do this
418-
// instead to avoid an abort.
419-
handler.emit_diagnostic(Diagnostic::new(
420-
Level::Bug,
421-
"It looks like you're trying to break rust; would you like some ICE?",
422-
));
423-
handler.note("the compiler expectedly panicked. this is a feature.");
424-
handler.note(
417+
let mut diag =
418+
handler.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(
425421
"we would appreciate a joke overview: \
426422
https://github.com/rust-lang/rust/issues/43162#issuecomment-320764675",
427423
);
428-
handler.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(),));
429425
if let Some((flags, excluded_cargo_defaults)) = rustc_session::utils::extra_compiler_flags() {
430-
handler.note(format!("compiler flags: {}", flags.join(" ")));
426+
diag.note(format!("compiler flags: {}", flags.join(" ")));
431427
if excluded_cargo_defaults {
432-
handler.note("some of the compiler flags provided by cargo are hidden");
428+
diag.note("some of the compiler flags provided by cargo are hidden");
433429
}
434430
}
431+
diag.emit();
435432
}
436433

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

tests/ui/track-diagnostics/track.stderr

+5-8
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ 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-
19-
note: we would appreciate a joke overview: https://github.com/rust-lang/rust/issues/43162#issuecomment-320764675
20-
21-
note: rustc $VERSION running on $TARGET
22-
23-
note: compiler flags: ... -Z ui-testing ... -Z track-diagnostics
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
2421

2522
error: aborting due to 3 previous errors
2623

0 commit comments

Comments
 (0)