Skip to content

Commit 9e872b7

Browse files
Rollup merge of #118933 - nnethercote:cleanup-errors-even-more, r=compiler-errors
Cleanup errors handlers even more A sequel to #118587. r? `@compiler-errors`
2 parents 576a74b + 9a78412 commit 9e872b7

File tree

23 files changed

+117
-113
lines changed

23 files changed

+117
-113
lines changed

compiler/rustc_borrowck/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2502,8 +2502,8 @@ mod error {
25022502
if !self.errors.buffered.is_empty() {
25032503
self.errors.buffered.sort_by_key(|diag| diag.sort_span);
25042504

2505-
for mut diag in self.errors.buffered.drain(..) {
2506-
self.infcx.tcx.sess.diagnostic().emit_diagnostic(&mut diag);
2505+
for diag in self.errors.buffered.drain(..) {
2506+
self.infcx.tcx.sess.diagnostic().emit_diagnostic(diag);
25072507
}
25082508
}
25092509

compiler/rustc_builtin_macros/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ impl<'a> IntoDiagnostic<'a> for EnvNotDefinedWithUserMessage {
453453
rustc::untranslatable_diagnostic,
454454
reason = "cannot translate user-provided messages"
455455
)]
456-
let mut diag = handler.struct_diagnostic(self.msg_from_user.to_string());
456+
let mut diag = handler.struct_err(self.msg_from_user.to_string());
457457
diag.set_span(self.span);
458458
diag
459459
}
@@ -804,7 +804,7 @@ pub(crate) struct AsmClobberNoReg {
804804
impl<'a> IntoDiagnostic<'a> for AsmClobberNoReg {
805805
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
806806
let mut diag =
807-
handler.struct_diagnostic(crate::fluent_generated::builtin_macros_asm_clobber_no_reg);
807+
handler.struct_err(crate::fluent_generated::builtin_macros_asm_clobber_no_reg);
808808
diag.set_span(self.spans.clone());
809809
// eager translation as `span_labels` takes `AsRef<str>`
810810
let lbl1 = handler.eagerly_translate_to_string(

compiler/rustc_codegen_llvm/src/errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ impl IntoDiagnostic<'_, FatalError> for ParseTargetMachineConfig<'_> {
107107
let (message, _) = diag.styled_message().first().expect("`LlvmError` with no message");
108108
let message = handler.eagerly_translate_to_string(message.clone(), diag.args());
109109

110-
let mut diag = handler.struct_diagnostic(fluent::codegen_llvm_parse_target_machine_config);
110+
let mut diag =
111+
handler.struct_almost_fatal(fluent::codegen_llvm_parse_target_machine_config);
111112
diag.set_arg("error", message);
112113
diag
113114
}

compiler/rustc_codegen_ssa/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ impl SharedEmitterMain {
18481848
d.code(code);
18491849
}
18501850
d.replace_args(diag.args);
1851-
handler.emit_diagnostic(&mut d);
1851+
handler.emit_diagnostic(d);
18521852
}
18531853
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
18541854
let msg = msg.strip_prefix("error: ").unwrap_or(&msg).to_string();

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
277277
// "secondary" errors if they occurred.
278278
let secondary_errors = mem::take(&mut self.secondary_errors);
279279
if self.error_emitted.is_none() {
280-
for mut error in secondary_errors {
281-
self.tcx.sess.diagnostic().emit_diagnostic(&mut error);
280+
for error in secondary_errors {
281+
self.tcx.sess.diagnostic().emit_diagnostic(error);
282282
}
283283
} else {
284284
assert!(self.tcx.sess.has_errors().is_some());

compiler/rustc_errors/src/diagnostic_builder.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl EmissionGuarantee for ErrorGuaranteed {
132132
DiagnosticBuilderState::Emittable(handler) => {
133133
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
134134

135-
let guar = handler.emit_diagnostic(&mut db.inner.diagnostic);
135+
let guar = handler.emit_diagnostic_without_consuming(&mut db.inner.diagnostic);
136136

137137
// Only allow a guarantee if the `level` wasn't switched to a
138138
// non-error - the field isn't `pub`, but the whole `Diagnostic`
@@ -181,7 +181,7 @@ impl EmissionGuarantee for () {
181181
DiagnosticBuilderState::Emittable(handler) => {
182182
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
183183

184-
handler.emit_diagnostic(&mut db.inner.diagnostic);
184+
handler.emit_diagnostic_without_consuming(&mut db.inner.diagnostic);
185185
}
186186
// `.emit()` was previously called, disallowed from repeating it.
187187
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
@@ -207,7 +207,7 @@ impl EmissionGuarantee for Noted {
207207
// First `.emit()` call, the `&Handler` is still available.
208208
DiagnosticBuilderState::Emittable(handler) => {
209209
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
210-
handler.emit_diagnostic(&mut db.inner.diagnostic);
210+
handler.emit_diagnostic_without_consuming(&mut db.inner.diagnostic);
211211
}
212212
// `.emit()` was previously called, disallowed from repeating it.
213213
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
@@ -236,7 +236,7 @@ impl EmissionGuarantee for Bug {
236236
DiagnosticBuilderState::Emittable(handler) => {
237237
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
238238

239-
handler.emit_diagnostic(&mut db.inner.diagnostic);
239+
handler.emit_diagnostic_without_consuming(&mut db.inner.diagnostic);
240240
}
241241
// `.emit()` was previously called, disallowed from repeating it.
242242
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
@@ -260,7 +260,7 @@ impl EmissionGuarantee for ! {
260260
DiagnosticBuilderState::Emittable(handler) => {
261261
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
262262

263-
handler.emit_diagnostic(&mut db.inner.diagnostic);
263+
handler.emit_diagnostic_without_consuming(&mut db.inner.diagnostic);
264264
}
265265
// `.emit()` was previously called, disallowed from repeating it.
266266
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
@@ -284,7 +284,7 @@ impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
284284
DiagnosticBuilderState::Emittable(handler) => {
285285
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
286286

287-
handler.emit_diagnostic(&mut db.inner.diagnostic);
287+
handler.emit_diagnostic_without_consuming(&mut db.inner.diagnostic);
288288
}
289289
// `.emit()` was previously called, disallowed from repeating it.
290290
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
@@ -365,7 +365,9 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
365365
}
366366
}
367367

368-
/// Emit the diagnostic.
368+
/// Emit the diagnostic. Does not consume `self`, which may be surprising,
369+
/// but there are various places that rely on continuing to use `self`
370+
/// after calling `emit`.
369371
#[track_caller]
370372
pub fn emit(&mut self) -> G {
371373
G::diagnostic_builder_emit_producing_guarantee(self)
@@ -640,13 +642,13 @@ impl Drop for DiagnosticBuilderInner<'_> {
640642
// No `.emit()` or `.cancel()` calls.
641643
DiagnosticBuilderState::Emittable(handler) => {
642644
if !panicking() {
643-
handler.emit_diagnostic(&mut Diagnostic::new(
645+
handler.emit_diagnostic(Diagnostic::new(
644646
Level::Bug,
645647
DiagnosticMessage::from(
646648
"the following error was constructed but not emitted",
647649
),
648650
));
649-
handler.emit_diagnostic(&mut self.diagnostic);
651+
handler.emit_diagnostic_without_consuming(&mut self.diagnostic);
650652
panic!("error was constructed but not emitted");
651653
}
652654
}

compiler/rustc_errors/src/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ impl Emitter for SilentEmitter {
581581
if let Some(ref note) = self.fatal_note {
582582
d.note(note.clone());
583583
}
584-
self.fatal_handler.emit_diagnostic(&mut d);
584+
self.fatal_handler.emit_diagnostic(d);
585585
}
586586
}
587587
}

0 commit comments

Comments
 (0)