Skip to content

Commit 23510b2

Browse files
committed
Split Level::DelayedBug in two.
The two kinds of delayed bug have quite different semantics so a stronger conceptual separation is nice. (`is_error` is a good example, because the two kinds have different behaviour.) The commit also 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. (The pre-existing `downgrade_to_delayed_bug` function also reflects the notion that delayed bugs are lower/after normal errors.) 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. Finally, it renames `DiagCtxtInner::span_delayed_bugs` as `DiagCtxtInner::delayed_bugs`. The `span_` prefix is unnecessary because some delayed bugs don't have a span.
1 parent b38c36b commit 23510b2

File tree

7 files changed

+101
-90
lines changed

7 files changed

+101
-90
lines changed

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 good_path_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

+5-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ 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
89+
| Level::Fatal
90+
| Level::Error
91+
| Level::DelayedBug
92+
| Level::GoodPathDelayedBug => AnnotationType::Error,
8993
Level::ForceWarning(_) | Level::Warning => AnnotationType::Warning,
9094
Level::Note | Level::OnceNote => AnnotationType::Note,
9195
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::GoodPathDelayedBug
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)