Skip to content

Commit 32803e1

Browse files
committed
Rename "good path delayed bugs" as "weak delayed bugs".
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`
1 parent b38c36b commit 32803e1

File tree

11 files changed

+122
-112
lines changed

11 files changed

+122
-112
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
287287
if tcx.def_key(self.instance.def_id()).disambiguated_data.data == DefPathData::Closure {
288288
write!(f, "inside closure")
289289
} else {
290-
// Note: this triggers a `good_path_delayed_bug` state, which means that if we ever
290+
// Note: this triggers a `weak_delayed_bug` state, which means that if we ever
291291
// get here we must emit a diagnostic. We should never display a `FrameInfo` unless
292292
// we actually want to emit a warning or error to the user.
293293
write!(f, "inside `{}`", self.instance)
@@ -303,7 +303,7 @@ impl<'tcx> FrameInfo<'tcx> {
303303
errors::FrameNote { where_: "closure", span, instance: String::new(), times: 0 }
304304
} else {
305305
let instance = format!("{}", self.instance);
306-
// Note: this triggers a `good_path_delayed_bug` state, which means that if we ever get
306+
// Note: this triggers a `weak_delayed_bug` state, which means that if we ever get
307307
// here we must emit a diagnostic. We should never display a `FrameInfo` unless we
308308
// actually want to emit a warning or error to the user.
309309
errors::FrameNote { where_: "instance", span, instance, times: 0 }

compiler/rustc_error_messages/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl From<Cow<'static, str>> for DiagnosticMessage {
378378
}
379379
}
380380

381-
/// A workaround for "good path" ICEs when formatting types in disabled lints.
381+
/// A workaround for weak_delayed_bug ICEs when formatting types in disabled lints.
382382
///
383383
/// Delays formatting until `.into(): DiagnosticMessage` is used.
384384
pub struct DelayDm<F>(pub F);

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
8585
/// Maps `Diagnostic::Level` to `snippet::AnnotationType`
8686
fn annotation_type_for_level(level: Level) -> AnnotationType {
8787
match level {
88-
Level::Bug | Level::DelayedBug(_) | Level::Fatal | Level::Error => AnnotationType::Error,
88+
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug | Level::WeakDelayedBug => {
89+
AnnotationType::Error
90+
}
8991
Level::ForceWarning(_) | Level::Warning => AnnotationType::Warning,
9092
Level::Note | Level::OnceNote => AnnotationType::Note,
9193
Level::Help | Level::OnceHelp => AnnotationType::Help,

compiler/rustc_errors/src/diagnostic.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::snippet::Style;
22
use crate::{
3-
CodeSuggestion, DelayedBugKind, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee,
4-
ErrCode, Level, MultiSpan, SubdiagnosticMessage, Substitution, SubstitutionPart,
5-
SuggestionStyle,
3+
CodeSuggestion, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, ErrCode, Level,
4+
MultiSpan, SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
65
};
76
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
87
use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
@@ -235,14 +234,11 @@ impl Diagnostic {
235234

236235
pub fn is_error(&self) -> bool {
237236
match self.level {
238-
Level::Bug
239-
| Level::DelayedBug(DelayedBugKind::Normal)
240-
| Level::Fatal
241-
| Level::Error => true,
237+
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => true,
242238

243-
Level::ForceWarning(_)
239+
Level::WeakDelayedBug
240+
| Level::ForceWarning(_)
244241
| Level::Warning
245-
| Level::DelayedBug(DelayedBugKind::GoodPath)
246242
| Level::Note
247243
| Level::OnceNote
248244
| Level::Help
@@ -306,11 +302,11 @@ impl Diagnostic {
306302
#[track_caller]
307303
pub fn downgrade_to_delayed_bug(&mut self) {
308304
assert!(
309-
matches!(self.level, Level::Error | Level::DelayedBug(_)),
305+
matches!(self.level, Level::Error | Level::DelayedBug),
310306
"downgrade_to_delayed_bug: cannot downgrade {:?} to DelayedBug: not an error",
311307
self.level
312308
);
313-
self.level = Level::DelayedBug(DelayedBugKind::Normal);
309+
self.level = Level::DelayedBug;
314310
}
315311

316312
/// Appends a labeled span to the diagnostic.

compiler/rustc_errors/src/emitter.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,7 @@ impl HumanEmitter {
21182118
}
21192119
if !self.short_message {
21202120
for child in children {
2121+
assert!(child.level.can_be_top_or_sub().1);
21212122
let span = &child.span;
21222123
if let Err(err) = self.emit_messages_default_inner(
21232124
span,

0 commit comments

Comments
 (0)