Only deduplicate stack traces for good path bugs
This commit is contained in:
parent
7c991868c6
commit
5d62a737d7
2 changed files with 23 additions and 15 deletions
|
@ -1199,8 +1199,8 @@ static DEFAULT_HOOK: LazyLock<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send +
|
||||||
};
|
};
|
||||||
|
|
||||||
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
|
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
|
||||||
// Don't do this for `ExplicitBug`, which has an unhelpful message and backtrace.
|
// Don't do this for `GoodPathBug`, which already emits its own more useful backtrace.
|
||||||
if !info.payload().is::<rustc_errors::ExplicitBug>() {
|
if !info.payload().is::<rustc_errors::GoodPathBug>() {
|
||||||
(*DEFAULT_HOOK)(info);
|
(*DEFAULT_HOOK)(info);
|
||||||
|
|
||||||
// Separate the output with an empty line
|
// Separate the output with an empty line
|
||||||
|
@ -1237,7 +1237,9 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
|
||||||
|
|
||||||
// a .span_bug or .bug call has already printed what
|
// a .span_bug or .bug call has already printed what
|
||||||
// it wants to print.
|
// it wants to print.
|
||||||
if !info.payload().is::<rustc_errors::ExplicitBug>() {
|
if !info.payload().is::<rustc_errors::ExplicitBug>()
|
||||||
|
&& !info.payload().is::<rustc_errors::GoodPathBug>()
|
||||||
|
{
|
||||||
let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
|
let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
|
||||||
handler.emit_diagnostic(&mut d);
|
handler.emit_diagnostic(&mut d);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,12 +40,13 @@ use rustc_span::source_map::SourceMap;
|
||||||
use rustc_span::HashStableContext;
|
use rustc_span::HashStableContext;
|
||||||
use rustc_span::{Loc, Span};
|
use rustc_span::{Loc, Span};
|
||||||
|
|
||||||
|
use std::any::Any;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::fmt;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{error, fmt};
|
|
||||||
|
|
||||||
use termcolor::{Color, ColorSpec};
|
use termcolor::{Color, ColorSpec};
|
||||||
|
|
||||||
|
@ -361,16 +362,11 @@ pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker};
|
||||||
|
|
||||||
/// Signifies that the compiler died with an explicit call to `.bug`
|
/// Signifies that the compiler died with an explicit call to `.bug`
|
||||||
/// or `.span_bug` rather than a failed assertion, etc.
|
/// or `.span_bug` rather than a failed assertion, etc.
|
||||||
#[derive(Copy, Clone, Debug)]
|
|
||||||
pub struct ExplicitBug;
|
pub struct ExplicitBug;
|
||||||
|
|
||||||
impl fmt::Display for ExplicitBug {
|
/// Signifies that the compiler died with an explicit call to `.delay_good_path_bug`
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
/// rather than a failed assertion, etc.
|
||||||
write!(f, "parser internal bug")
|
pub struct GoodPathBug;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl error::Error for ExplicitBug {}
|
|
||||||
|
|
||||||
pub use diagnostic::{
|
pub use diagnostic::{
|
||||||
AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
|
AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
|
||||||
|
@ -507,7 +503,11 @@ impl Drop for HandlerInner {
|
||||||
|
|
||||||
if !self.has_errors() {
|
if !self.has_errors() {
|
||||||
let bugs = std::mem::replace(&mut self.delayed_span_bugs, Vec::new());
|
let bugs = std::mem::replace(&mut self.delayed_span_bugs, Vec::new());
|
||||||
self.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued");
|
self.flush_delayed(
|
||||||
|
bugs,
|
||||||
|
"no errors encountered even though `delay_span_bug` issued",
|
||||||
|
ExplicitBug,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(eddyb) this explains what `delayed_good_path_bugs` are!
|
// FIXME(eddyb) this explains what `delayed_good_path_bugs` are!
|
||||||
|
@ -520,6 +520,7 @@ impl Drop for HandlerInner {
|
||||||
self.flush_delayed(
|
self.flush_delayed(
|
||||||
bugs.into_iter().map(DelayedDiagnostic::decorate),
|
bugs.into_iter().map(DelayedDiagnostic::decorate),
|
||||||
"no warnings or errors encountered even though `delayed_good_path_bugs` issued",
|
"no warnings or errors encountered even though `delayed_good_path_bugs` issued",
|
||||||
|
GoodPathBug,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1203,7 +1204,11 @@ impl Handler {
|
||||||
pub fn flush_delayed(&self) {
|
pub fn flush_delayed(&self) {
|
||||||
let mut inner = self.inner.lock();
|
let mut inner = self.inner.lock();
|
||||||
let bugs = std::mem::replace(&mut inner.delayed_span_bugs, Vec::new());
|
let bugs = std::mem::replace(&mut inner.delayed_span_bugs, Vec::new());
|
||||||
inner.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued");
|
inner.flush_delayed(
|
||||||
|
bugs,
|
||||||
|
"no errors encountered even though `delay_span_bug` issued",
|
||||||
|
ExplicitBug,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1580,6 +1585,7 @@ impl HandlerInner {
|
||||||
&mut self,
|
&mut self,
|
||||||
bugs: impl IntoIterator<Item = Diagnostic>,
|
bugs: impl IntoIterator<Item = Diagnostic>,
|
||||||
explanation: impl Into<DiagnosticMessage> + Copy,
|
explanation: impl Into<DiagnosticMessage> + Copy,
|
||||||
|
panic_with: impl Any + Send + 'static,
|
||||||
) {
|
) {
|
||||||
let mut no_bugs = true;
|
let mut no_bugs = true;
|
||||||
for mut bug in bugs {
|
for mut bug in bugs {
|
||||||
|
@ -1607,7 +1613,7 @@ impl HandlerInner {
|
||||||
|
|
||||||
// Panic with `ExplicitBug` to avoid "unexpected panic" messages.
|
// Panic with `ExplicitBug` to avoid "unexpected panic" messages.
|
||||||
if !no_bugs {
|
if !no_bugs {
|
||||||
panic::panic_any(ExplicitBug);
|
panic::panic_any(panic_with);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue