Skip to content

Commit bfb54c6

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 a91cd99 commit bfb54c6

File tree

1 file changed

+8
-22
lines changed
  • compiler/rustc_errors/src

1 file changed

+8
-22
lines changed

compiler/rustc_errors/src/lib.rs

+8-22
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,7 @@ impl Handler {
982982
#[rustc_lint_diagnostics]
983983
#[track_caller]
984984
pub fn span_fatal(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
985-
self.emit_diag_at_span(Diagnostic::new(Fatal, msg), span);
986-
FatalError.raise()
985+
self.struct_span_fatal(span, msg).emit()
987986
}
988987

989988
#[rustc_lint_diagnostics]
@@ -994,8 +993,7 @@ impl Handler {
994993
msg: impl Into<DiagnosticMessage>,
995994
code: DiagnosticId,
996995
) -> ! {
997-
self.emit_diag_at_span(Diagnostic::new_with_code(Fatal, Some(code), msg), span);
998-
FatalError.raise()
996+
self.struct_span_fatal_with_code(span, msg, code).emit()
999997
}
1000998

1001999
#[rustc_lint_diagnostics]
@@ -1005,7 +1003,7 @@ impl Handler {
10051003
span: impl Into<MultiSpan>,
10061004
msg: impl Into<DiagnosticMessage>,
10071005
) -> ErrorGuaranteed {
1008-
self.emit_diag_at_span(Diagnostic::new(Error { lint: false }, msg), span).unwrap()
1006+
self.struct_span_err(span, msg).emit()
10091007
}
10101008

10111009
#[rustc_lint_diagnostics]
@@ -1016,17 +1014,13 @@ impl Handler {
10161014
msg: impl Into<DiagnosticMessage>,
10171015
code: DiagnosticId,
10181016
) -> ErrorGuaranteed {
1019-
self.emit_diag_at_span(
1020-
Diagnostic::new_with_code(Error { lint: false }, Some(code), msg),
1021-
span,
1022-
)
1023-
.unwrap()
1017+
self.struct_span_err_with_code(span, msg, code).emit()
10241018
}
10251019

10261020
#[rustc_lint_diagnostics]
10271021
#[track_caller]
10281022
pub fn span_warn(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) {
1029-
self.emit_diag_at_span(Diagnostic::new(Warning(None), msg), span);
1023+
self.struct_span_warn(span, msg).emit()
10301024
}
10311025

10321026
#[rustc_lint_diagnostics]
@@ -1037,7 +1031,7 @@ impl Handler {
10371031
msg: impl Into<DiagnosticMessage>,
10381032
code: DiagnosticId,
10391033
) {
1040-
self.emit_diag_at_span(Diagnostic::new_with_code(Warning(None), Some(code), msg), span);
1034+
self.struct_span_warn_with_code(span, msg, code).emit()
10411035
}
10421036

10431037
pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
@@ -1086,14 +1080,14 @@ impl Handler {
10861080
#[track_caller]
10871081
#[rustc_lint_diagnostics]
10881082
pub fn span_note(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) {
1089-
self.emit_diag_at_span(Diagnostic::new(Note, msg), span);
1083+
self.struct_span_note(span, msg).emit()
10901084
}
10911085

10921086
#[track_caller]
10931087
#[rustc_lint_diagnostics]
10941088
pub fn struct_span_note(
10951089
&self,
1096-
span: Span,
1090+
span: impl Into<MultiSpan>,
10971091
msg: impl Into<DiagnosticMessage>,
10981092
) -> DiagnosticBuilder<'_, ()> {
10991093
let mut db = DiagnosticBuilder::new(self, Note, msg);
@@ -1338,14 +1332,6 @@ impl Handler {
13381332
note.into_diagnostic(self)
13391333
}
13401334

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

0 commit comments

Comments
 (0)