Skip to content

Commit

Permalink
Rename "good path delayed bugs" as "weak delayed bugs".
Browse files Browse the repository at this point in the history
Because they're like delayed bugs, but weaker, e.g. they don't provide
an `ErrorGuaranteed`.

This lets us remove of some old FIXME comments complaining about the
"good path" name.

The commit also splits `Level::DelayedBug` into two parts rather than
using a parameter. The two kinds of delayed bug have quite different
semantics so a stronger conceptual separation is nice.

Plus it moves the `DelayedBug` variant after `Error` in `Level`, to
reflect the fact that it's weaker than `Error` -- it might trigger an
error but also might not.

Plus it condenses some of the comments on `Level` into a table, for
easier reading, and introduces `can_be_top_or_sub` to indicate which
levels can be used in top-level diagnostics vs. subdiagnostics.

Things renamed:
- `DiagCtxtInner::good_path_delayed_bugs` -> `DiagCtxtInner::weak_delayed_bugs`
- `DiagCtxtInner::span_delayed_bugs` -> `DiagCtxtInner::delayed_bugs`
- `DelayedBugKind::GoodPath` -> `DelayedBugKind::Weak`
  • Loading branch information
nnethercote committed Jan 31, 2024
1 parent b38c36b commit 56cd3d2
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 112 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
if tcx.def_key(self.instance.def_id()).disambiguated_data.data == DefPathData::Closure {
write!(f, "inside closure")
} else {
// Note: this triggers a `good_path_delayed_bug` state, which means that if we ever
// Note: this triggers a `weak_delayed_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.
write!(f, "inside `{}`", self.instance)
Expand All @@ -303,7 +303,7 @@ impl<'tcx> FrameInfo<'tcx> {
errors::FrameNote { where_: "closure", span, instance: String::new(), times: 0 }
} else {
let instance = format!("{}", self.instance);
// Note: this triggers a `good_path_delayed_bug` state, which means that if we ever get
// Note: this triggers a `weak_delayed_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.
errors::FrameNote { where_: "instance", span, instance, times: 0 }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl From<Cow<'static, str>> for DiagnosticMessage {
}
}

/// A workaround for "good path" ICEs when formatting types in disabled lints.
/// A workaround for weak_delayed_bug ICEs when formatting types in disabled lints.
///
/// Delays formatting until `.into(): DiagnosticMessage` is used.
pub struct DelayDm<F>(pub F);
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
/// Maps `Diagnostic::Level` to `snippet::AnnotationType`
fn annotation_type_for_level(level: Level) -> AnnotationType {
match level {
Level::Bug | Level::DelayedBug(_) | Level::Fatal | Level::Error => AnnotationType::Error,
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug | Level::WeakDelayedBug => {
AnnotationType::Error
}
Level::ForceWarning(_) | Level::Warning => AnnotationType::Warning,
Level::Note | Level::OnceNote => AnnotationType::Note,
Level::Help | Level::OnceHelp => AnnotationType::Help,
Expand Down
18 changes: 7 additions & 11 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::snippet::Style;
use crate::{
CodeSuggestion, DelayedBugKind, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee,
ErrCode, Level, MultiSpan, SubdiagnosticMessage, Substitution, SubstitutionPart,
SuggestionStyle,
CodeSuggestion, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, ErrCode, Level,
MultiSpan, SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
};
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
Expand Down Expand Up @@ -235,14 +234,11 @@ impl Diagnostic {

pub fn is_error(&self) -> bool {
match self.level {
Level::Bug
| Level::DelayedBug(DelayedBugKind::Normal)
| Level::Fatal
| Level::Error => true,
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => true,

Level::ForceWarning(_)
Level::WeakDelayedBug
| Level::ForceWarning(_)
| Level::Warning
| Level::DelayedBug(DelayedBugKind::GoodPath)
| Level::Note
| Level::OnceNote
| Level::Help
Expand Down Expand Up @@ -306,11 +302,11 @@ impl Diagnostic {
#[track_caller]
pub fn downgrade_to_delayed_bug(&mut self) {
assert!(
matches!(self.level, Level::Error | Level::DelayedBug(_)),
matches!(self.level, Level::Error | Level::DelayedBug),
"downgrade_to_delayed_bug: cannot downgrade {:?} to DelayedBug: not an error",
self.level
);
self.level = Level::DelayedBug(DelayedBugKind::Normal);
self.level = Level::DelayedBug;
}

/// Appends a labeled span to the diagnostic.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2118,6 +2118,7 @@ impl HumanEmitter {
}
if !self.short_message {
for child in children {
assert!(child.level.can_be_top_or_sub().1);
let span = &child.span;
if let Err(err) = self.emit_messages_default_inner(
span,
Expand Down
Loading

0 comments on commit 56cd3d2

Please sign in to comment.