mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
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.
This commit is contained in:
parent
072c157d68
commit
286329870d
@ -968,6 +968,19 @@ impl DiagCtxt {
|
||||
DiagnosticBuilder::new(self, Level::Bug, msg)
|
||||
}
|
||||
|
||||
/// Construct a builder at the `Bug` level at the given `span` with the `msg`.
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_span_bug(
|
||||
&self,
|
||||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, BugAbort> {
|
||||
let mut result = self.struct_bug(msg);
|
||||
result.set_span(span);
|
||||
result
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn span_fatal(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
|
||||
|
@ -722,7 +722,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
if let [segment] = path.segments
|
||||
&& segment.ident.name == sym::rust
|
||||
{
|
||||
fatally_break_rust(self.tcx);
|
||||
fatally_break_rust(self.tcx, expr.span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ use crate::expectation::Expectation;
|
||||
use crate::fn_ctxt::RawTy;
|
||||
use crate::gather_locals::GatherLocalsVisitor;
|
||||
use rustc_data_structures::unord::UnordSet;
|
||||
use rustc_errors::{struct_span_err, DiagnosticId, ErrorGuaranteed, MultiSpan};
|
||||
use rustc_errors::{struct_span_err, DiagnosticId, ErrorGuaranteed};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
@ -412,24 +412,25 @@ enum TupleArgumentsFlag {
|
||||
TupleArguments,
|
||||
}
|
||||
|
||||
fn fatally_break_rust(tcx: TyCtxt<'_>) {
|
||||
fn fatally_break_rust(tcx: TyCtxt<'_>, span: Span) -> ! {
|
||||
let dcx = tcx.sess.dcx();
|
||||
dcx.span_bug_no_panic(
|
||||
MultiSpan::new(),
|
||||
let mut diag = dcx.struct_span_bug(
|
||||
span,
|
||||
"It looks like you're trying to break rust; would you like some ICE?",
|
||||
);
|
||||
dcx.note("the compiler expectedly panicked. this is a feature.");
|
||||
dcx.note(
|
||||
diag.note("the compiler expectedly panicked. this is a feature.");
|
||||
diag.note(
|
||||
"we would appreciate a joke overview: \
|
||||
https://github.com/rust-lang/rust/issues/43162#issuecomment-320764675",
|
||||
);
|
||||
dcx.note(format!("rustc {} running on {}", tcx.sess.cfg_version, config::host_triple(),));
|
||||
diag.note(format!("rustc {} running on {}", tcx.sess.cfg_version, config::host_triple(),));
|
||||
if let Some((flags, excluded_cargo_defaults)) = rustc_session::utils::extra_compiler_flags() {
|
||||
dcx.note(format!("compiler flags: {}", flags.join(" ")));
|
||||
diag.note(format!("compiler flags: {}", flags.join(" ")));
|
||||
if excluded_cargo_defaults {
|
||||
dcx.note("some of the compiler flags provided by cargo are hidden");
|
||||
diag.note("some of the compiler flags provided by cargo are hidden");
|
||||
}
|
||||
}
|
||||
diag.emit()
|
||||
}
|
||||
|
||||
/// `expected` here is the expected number of explicit generic arguments on the trait.
|
||||
|
@ -1,5 +1,7 @@
|
||||
// compile-flags: -Z track-diagnostics
|
||||
// error-pattern: created at
|
||||
// rustc-env:RUST_BACKTRACE=0
|
||||
// failure-status: 101
|
||||
|
||||
// Normalize the emitted location so this doesn't need
|
||||
// updating everytime someone adds or removes a line.
|
||||
|
@ -13,15 +13,31 @@ LL | break rust
|
||||
-Ztrack-diagnostics: created at compiler/rustc_passes/src/loops.rs:LL:CC
|
||||
|
||||
error: internal compiler error: It looks like you're trying to break rust; would you like some ICE?
|
||||
--> $DIR/track.rs:LL:CC
|
||||
|
|
||||
LL | break rust
|
||||
| ^^^^^^^^^^
|
||||
-Ztrack-diagnostics: created at compiler/rustc_hir_typeck/src/lib.rs:LL:CC
|
||||
|
|
||||
= note: the compiler expectedly panicked. this is a feature.
|
||||
= note: we would appreciate a joke overview: https://github.com/rust-lang/rust/issues/43162#issuecomment-320764675
|
||||
= note: rustc $VERSION running on $TARGET
|
||||
= note: compiler flags: ... -Z ui-testing ... -Z track-diagnostics
|
||||
|
||||
note: the compiler expectedly panicked. this is a feature.
|
||||
thread 'rustc' panicked at compiler/rustc_hir_typeck/src/lib.rs:LL:CC:
|
||||
Box<dyn Any>
|
||||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
||||
|
||||
note: we would appreciate a joke overview: https://github.com/rust-lang/rust/issues/43162#issuecomment-320764675
|
||||
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
|
||||
|
||||
note: rustc $VERSION running on $TARGET
|
||||
|
||||
note: compiler flags: ... -Z ui-testing ... -Z track-diagnostics
|
||||
|
||||
query stack during panic:
|
||||
#0 [typeck] type-checking `main`
|
||||
#1 [analysis] running analysis passes on this crate
|
||||
end of query stack
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0268, E0425.
|
||||
|
Loading…
Reference in New Issue
Block a user