Skip to content

Commit a91cd99

Browse files
committed
Avoid DiagnosticBuilder::<T>::new calls.
The `Handler` functions that directly emit diagnostics can be more easily implemented using `struct_foo(msg).emit()`. This mirrors `Handler::emit_err` which just does `create_err(err).emit()`. One nice side-effect is that this removes the need for the `panic_any` call in `Handler::bug`, because the `emit` call does the panic. (This required adding `Handler::struct_bug`, which was missing.)
1 parent 6adfb74 commit a91cd99

File tree

1 file changed

+12
-6
lines changed
  • compiler/rustc_errors/src

1 file changed

+12
-6
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,13 @@ impl Handler {
972972
DiagnosticBuilder::new(self, Level::Note, msg)
973973
}
974974

975+
/// Construct a builder at the `Bug` level with the `msg`.
976+
#[rustc_lint_diagnostics]
977+
#[track_caller]
978+
pub fn struct_bug(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
979+
DiagnosticBuilder::new(self, Level::Bug, msg)
980+
}
981+
975982
#[rustc_lint_diagnostics]
976983
#[track_caller]
977984
pub fn span_fatal(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
@@ -1096,27 +1103,26 @@ impl Handler {
10961103

10971104
#[rustc_lint_diagnostics]
10981105
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> ! {
1099-
DiagnosticBuilder::<FatalError>::new(self, Fatal, msg).emit().raise()
1106+
self.struct_fatal(msg).emit()
11001107
}
11011108

11021109
#[rustc_lint_diagnostics]
11031110
pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
1104-
DiagnosticBuilder::<ErrorGuaranteed>::new(self, Error { lint: false }, msg).emit()
1111+
self.struct_err(msg).emit()
11051112
}
11061113

11071114
#[rustc_lint_diagnostics]
11081115
pub fn warn(&self, msg: impl Into<DiagnosticMessage>) {
1109-
DiagnosticBuilder::<()>::new(self, Warning(None), msg).emit();
1116+
self.struct_warn(msg).emit()
11101117
}
11111118

11121119
#[rustc_lint_diagnostics]
11131120
pub fn note(&self, msg: impl Into<DiagnosticMessage>) {
1114-
DiagnosticBuilder::<()>::new(self, Note, msg).emit();
1121+
self.struct_note(msg).emit()
11151122
}
11161123

11171124
pub fn bug(&self, msg: impl Into<DiagnosticMessage>) -> ! {
1118-
DiagnosticBuilder::<diagnostic_builder::Bug>::new(self, Bug, msg).emit();
1119-
panic::panic_any(ExplicitBug);
1125+
self.struct_bug(msg).emit()
11201126
}
11211127

11221128
#[inline]

0 commit comments

Comments
 (0)