Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
{
write!(f, "inside closure")
} else {
// Note: this triggers a `good_path_bug` state, which means that if we ever get here
// we must emit a diagnostic. We should never display a `FrameInfo` unless we
// actually want to emit a warning or error to the user.
// Note: this triggers a `bug_unless_diagnostic_emitted` state, which means
// that if we ever get here we must emit a diagnostic. We should never display
// a `FrameInfo` unless we actually want to emit a warning or error to the user.
write!(f, "inside `{}`", self.instance)
}
})
Expand Down
32 changes: 15 additions & 17 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,10 @@ struct HandlerInner {
deduplicated_err_count: usize,
emitter: Box<dyn Emitter + sync::Send>,
delayed_span_bugs: Vec<DelayedDiagnostic>,
delayed_good_path_bugs: Vec<DelayedDiagnostic>,
/// Bugs that are delayed unless a diagnostic (warn/lint/error) is emitted.
delayed_expect_diagnostic_bugs: Vec<DelayedDiagnostic>,
/// This flag indicates that an expected diagnostic was emitted and suppressed.
/// This is used for the `delayed_good_path_bugs` check.
/// This is used for the `delayed_bugs_unless_diagnostic_emitted` check.
suppressed_expected_diag: bool,

/// This set contains the `DiagnosticId` of all emitted diagnostics to avoid
Expand Down Expand Up @@ -520,16 +521,14 @@ impl Drop for HandlerInner {
self.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued");
}

// FIXME(eddyb) this explains what `delayed_good_path_bugs` are!
// They're `delayed_span_bugs` but for "require some diagnostic happened"
// instead of "require some error happened". Sadly that isn't ideal, as
// lints can be `#[allow]`'d, potentially leading to this triggering.
// Also, "good path" should be replaced with a better naming.
if !self.has_any_message() && !self.suppressed_expected_diag {
let bugs = std::mem::replace(&mut self.delayed_good_path_bugs, Vec::new());
let bugs = std::mem::replace(&mut self.delayed_expect_diagnostic_bugs, Vec::new());
self.flush_delayed(
bugs,
"no warnings or errors encountered even though `delayed_good_path_bugs` issued",
"no warnings or errors encountered even though `delayed_bugs_unless_diagnostic_emitted` issued",
);
}

Expand Down Expand Up @@ -608,7 +607,7 @@ impl Handler {
deduplicated_warn_count: 0,
emitter,
delayed_span_bugs: Vec::new(),
delayed_good_path_bugs: Vec::new(),
delayed_expect_diagnostic_bugs: Vec::new(),
suppressed_expected_diag: false,
taught_diagnostics: Default::default(),
emitted_diagnostic_codes: Default::default(),
Expand Down Expand Up @@ -662,7 +661,7 @@ impl Handler {

// actually free the underlying memory (which `clear` would not do)
inner.delayed_span_bugs = Default::default();
inner.delayed_good_path_bugs = Default::default();
inner.delayed_expect_diagnostic_bugs = Default::default();
inner.taught_diagnostics = Default::default();
inner.emitted_diagnostic_codes = Default::default();
inner.emitted_diagnostics = Default::default();
Expand Down Expand Up @@ -1005,10 +1004,9 @@ impl Handler {
self.inner.borrow_mut().delay_span_bug(span, msg)
}

// FIXME(eddyb) note the comment inside `impl Drop for HandlerInner`, that's
// where the explanation of what "good path" is (also, it should be renamed).
pub fn delay_good_path_bug(&self, msg: impl Into<DiagnosticMessage>) {
self.inner.borrow_mut().delay_good_path_bug(msg)
// FIXME(eddyb) note the comment inside `impl Drop for HandlerInner`.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what this FIXME is actually asking for... to copy the explanation and give this function a good doc comment? I'm gonna leave it for now lol.

pub fn delay_bug_unless_diagnostic_emitted(&self, msg: impl Into<DiagnosticMessage>) {
self.inner.borrow_mut().delay_bug_unless_diagnostic_emitted(msg)
}

#[track_caller]
Expand Down Expand Up @@ -1436,7 +1434,7 @@ impl HandlerInner {
}

fn delayed_bug_count(&self) -> usize {
self.delayed_span_bugs.len() + self.delayed_good_path_bugs.len()
self.delayed_span_bugs.len() + self.delayed_expect_diagnostic_bugs.len()
}

fn print_error_count(&mut self, registry: &Registry) {
Expand Down Expand Up @@ -1609,15 +1607,15 @@ impl HandlerInner {
self.emit_diagnostic(&mut diagnostic).unwrap()
}

// FIXME(eddyb) note the comment inside `impl Drop for HandlerInner`, that's
// where the explanation of what "good path" is (also, it should be renamed).
fn delay_good_path_bug(&mut self, msg: impl Into<DiagnosticMessage>) {
// FIXME(eddyb) note the comment inside `impl Drop for HandlerInner`.
fn delay_bug_unless_diagnostic_emitted(&mut self, msg: impl Into<DiagnosticMessage>) {
let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg);
if self.flags.report_delayed_bugs {
self.emit_diagnostic(&mut diagnostic);
}
let backtrace = std::backtrace::Backtrace::force_capture();
self.delayed_good_path_bugs.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
self.delayed_expect_diagnostic_bugs
.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
}

fn failure(&mut self, msg: impl Into<DiagnosticMessage>) {
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2947,8 +2947,9 @@ fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> FxHashMap<DefId, Symbol> {
//
// For good paths causing this bug, the `rustc_middle::ty::print::with_no_trimmed_paths`
// wrapper can be used to suppress this query, in exchange for full paths being formatted.
tcx.sess.delay_good_path_bug(
"trimmed_def_paths constructed but no error emitted; use `DelayDm` for lints or `with_no_trimmed_paths` for debugging",
tcx.sess.delay_bug_unless_diagnostic_emitted(
"trimmed_def_paths constructed but no diagnostic emitted; \
use `DelayDm` for lints or `with_no_trimmed_paths` for debugging",
);
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ pub enum TrimmedDefPaths {
/// `try_print_trimmed_def_path` never prints a trimmed path and never calls the expensive query
#[default]
Never,
/// `try_print_trimmed_def_path` calls the expensive query, the query doesn't call `delay_good_path_bug`
/// `try_print_trimmed_def_path` calls the expensive query, the query doesn't call `delay_bug_unless_diagnostic_emitted`
Always,
/// `try_print_trimmed_def_path` calls the expensive query, the query calls `delay_good_path_bug`
/// `try_print_trimmed_def_path` calls the expensive query, the query calls `delay_bug_unless_diagnostic_emitted`
GoodPath,
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ impl Session {
/// Used for code paths of expensive computations that should only take place when
/// warnings or errors are emitted. If no messages are emitted ("good path"), then
/// it's likely a bug.
pub fn delay_good_path_bug(&self, msg: impl Into<DiagnosticMessage>) {
pub fn delay_bug_unless_diagnostic_emitted(&self, msg: impl Into<DiagnosticMessage>) {
if self.opts.unstable_opts.print_type_sizes
|| self.opts.unstable_opts.query_dep_graph
|| self.opts.unstable_opts.dump_mir.is_some()
Expand All @@ -642,7 +642,7 @@ impl Session {
return;
}

self.diagnostic().delay_good_path_bug(msg)
self.diagnostic().delay_bug_unless_diagnostic_emitted(msg)
}

#[rustc_lint_diagnostics]
Expand Down Expand Up @@ -892,7 +892,7 @@ impl Session {
if fuel.remaining == 0 && !fuel.out_of_fuel {
if self.diagnostic().can_emit_warnings() {
// We only call `msg` in case we can actually emit warnings.
// Otherwise, this could cause a `delay_good_path_bug` to
// Otherwise, this could cause a `delay_bug_unless_diagnostic_emitted` to
// trigger (issue #79546).
self.emit_warning(errors::OptimisationFuelExhausted { msg: msg() });
}
Expand Down