Skip to content

Commit 2c2c7f1

Browse files
committed
Remove Handler::emit_diag_at_span.
Compare `Handler::warn` and `Handler::span_warn`. Conceptually they are almost identical. But their implementations are weirdly different. `warn`: - calls `DiagnosticBuilder::<()>::new(self, Warning(None), msg)`, then `emit()` - which calls `G::diagnostic_builder_emit_producing_guarantee(self)` - which calls `handler.emit_diagnostic(&mut db.inner.diagnostic)` `span_warn`: - calls `self.emit_diag_at_span(Diagnostic::new(Warning(None), msg), span)` - which calls `self.emit_diagnostic(diag.set_span(sp))` I.e. they both end up at `emit_diagnostic`, but take very different routes to get there. This commit changes `span_*` and similar ones to not use `emit_diag_at_span`. Instead they just call `struct_span_*` + `emit`. Some nice side-effects of this: - `span_fatal` and `span_fatal_with_code` don't need `FatalError.raise()`, because `emit` does that. - `span_err` and `span_err_with_code` doesn't need `unwrap`. - `struct_span_note`'s `span` arg type is changed from `Span` to `impl Into<MultiSpan>` like all the other functions.
1 parent b0d5b44 commit 2c2c7f1

File tree

1 file changed

+9
-23
lines changed
  • compiler/rustc_errors/src

1 file changed

+9
-23
lines changed

compiler/rustc_errors/src/lib.rs

+9-23
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,7 @@ impl Handler {
975975
#[rustc_lint_diagnostics]
976976
#[track_caller]
977977
pub fn span_fatal(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
978-
self.emit_diag_at_span(Diagnostic::new(Fatal, msg), span);
979-
FatalError.raise()
978+
self.struct_span_fatal(span, msg).emit()
980979
}
981980

982981
#[rustc_lint_diagnostics]
@@ -987,8 +986,7 @@ impl Handler {
987986
msg: impl Into<DiagnosticMessage>,
988987
code: DiagnosticId,
989988
) -> ! {
990-
self.emit_diag_at_span(Diagnostic::new_with_code(Fatal, Some(code), msg), span);
991-
FatalError.raise()
989+
self.struct_span_fatal_with_code(span, msg, code).emit()
992990
}
993991

994992
#[rustc_lint_diagnostics]
@@ -998,7 +996,7 @@ impl Handler {
998996
span: impl Into<MultiSpan>,
999997
msg: impl Into<DiagnosticMessage>,
1000998
) -> ErrorGuaranteed {
1001-
self.emit_diag_at_span(Diagnostic::new(Error { lint: false }, msg), span).unwrap()
999+
self.struct_span_err(span, msg).emit()
10021000
}
10031001

10041002
#[rustc_lint_diagnostics]
@@ -1009,17 +1007,13 @@ impl Handler {
10091007
msg: impl Into<DiagnosticMessage>,
10101008
code: DiagnosticId,
10111009
) -> ErrorGuaranteed {
1012-
self.emit_diag_at_span(
1013-
Diagnostic::new_with_code(Error { lint: false }, Some(code), msg),
1014-
span,
1015-
)
1016-
.unwrap()
1010+
self.struct_span_err_with_code(span, msg, code).emit()
10171011
}
10181012

10191013
#[rustc_lint_diagnostics]
10201014
#[track_caller]
10211015
pub fn span_warn(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) {
1022-
self.emit_diag_at_span(Diagnostic::new(Warning(None), msg), span);
1016+
self.struct_span_warn(span, msg).emit()
10231017
}
10241018

10251019
#[rustc_lint_diagnostics]
@@ -1030,7 +1024,7 @@ impl Handler {
10301024
msg: impl Into<DiagnosticMessage>,
10311025
code: DiagnosticId,
10321026
) {
1033-
self.emit_diag_at_span(Diagnostic::new_with_code(Warning(None), Some(code), msg), span);
1027+
self.struct_span_warn_with_code(span, msg, code).emit()
10341028
}
10351029

10361030
pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
@@ -1078,20 +1072,20 @@ impl Handler {
10781072

10791073
#[track_caller]
10801074
pub fn span_bug_no_panic(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) {
1081-
self.emit_diag_at_span(Diagnostic::new(Bug, msg), span);
1075+
self.emit_diagnostic(Diagnostic::new(Bug, msg).set_span(span));
10821076
}
10831077

10841078
#[track_caller]
10851079
#[rustc_lint_diagnostics]
10861080
pub fn span_note(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) {
1087-
self.emit_diag_at_span(Diagnostic::new(Note, msg), span);
1081+
self.struct_span_note(span, msg).emit()
10881082
}
10891083

10901084
#[track_caller]
10911085
#[rustc_lint_diagnostics]
10921086
pub fn struct_span_note(
10931087
&self,
1094-
span: Span,
1088+
span: impl Into<MultiSpan>,
10951089
msg: impl Into<DiagnosticMessage>,
10961090
) -> DiagnosticBuilder<'_, ()> {
10971091
let mut db = DiagnosticBuilder::new(self, Note, msg);
@@ -1337,14 +1331,6 @@ impl Handler {
13371331
note.into_diagnostic(self)
13381332
}
13391333

1340-
fn emit_diag_at_span(
1341-
&self,
1342-
mut diag: Diagnostic,
1343-
sp: impl Into<MultiSpan>,
1344-
) -> Option<ErrorGuaranteed> {
1345-
self.emit_diagnostic(diag.set_span(sp))
1346-
}
1347-
13481334
pub fn emit_artifact_notification(&self, path: &Path, artifact_type: &str) {
13491335
self.inner.borrow_mut().emitter.emit_artifact_notification(path, artifact_type);
13501336
}

0 commit comments

Comments
 (0)