Skip to content

Commit f361b59

Browse files
Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errors
Cleanup error handlers: round 5 More rustc_errors cleanups. A sequel to #119171. r? ````@compiler-errors````
2 parents f41ad1b + 8388112 commit f361b59

File tree

57 files changed

+369
-464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+369
-464
lines changed

compiler/rustc_ast_passes/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,8 @@ impl AddToDiagnostic for StableFeature {
725725
rustc_errors::SubdiagnosticMessage,
726726
) -> rustc_errors::SubdiagnosticMessage,
727727
{
728-
diag.set_arg("name", self.name);
729-
diag.set_arg("since", self.since);
728+
diag.arg("name", self.name);
729+
diag.arg("since", self.since);
730730
diag.help(fluent::ast_passes_stable_since);
731731
}
732732
}

compiler/rustc_attr/src/session_diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnknownMetaItem<'_> {
5555
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
5656
let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
5757
let mut diag = DiagnosticBuilder::new(dcx, level, fluent::attr_unknown_meta_item);
58-
diag.set_span(self.span);
58+
diag.span(self.span);
5959
diag.code(error_code!(E0541));
60-
diag.set_arg("item", self.item);
61-
diag.set_arg("expected", expected.join(", "));
60+
diag.arg("item", self.item);
61+
diag.arg("expected", expected.join(", "));
6262
diag.span_label(self.span, fluent::attr_label);
6363
diag
6464
}
@@ -215,7 +215,7 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnsupportedLiteral {
215215
}
216216
},
217217
);
218-
diag.set_span(self.span);
218+
diag.span(self.span);
219219
diag.code(error_code!(E0565));
220220
if self.is_bytestr {
221221
diag.span_suggestion(

compiler/rustc_builtin_macros/src/errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for EnvNotDefinedWithUserMe
454454
reason = "cannot translate user-provided messages"
455455
)]
456456
let mut diag = DiagnosticBuilder::new(dcx, level, self.msg_from_user.to_string());
457-
diag.set_span(self.span);
457+
diag.span(self.span);
458458
diag
459459
}
460460
}
@@ -618,7 +618,7 @@ impl AddToDiagnostic for FormatUnusedArg {
618618
rustc_errors::SubdiagnosticMessage,
619619
) -> rustc_errors::SubdiagnosticMessage,
620620
{
621-
diag.set_arg("named", self.named);
621+
diag.arg("named", self.named);
622622
let msg = f(diag, crate::fluent_generated::builtin_macros_format_unused_arg.into());
623623
diag.span_label(self.span, msg);
624624
}
@@ -808,7 +808,7 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for AsmClobberNoReg {
808808
level,
809809
crate::fluent_generated::builtin_macros_asm_clobber_no_reg,
810810
);
811-
diag.set_span(self.spans.clone());
811+
diag.span(self.spans.clone());
812812
// eager translation as `span_labels` takes `AsRef<str>`
813813
let lbl1 = dcx.eagerly_translate_to_string(
814814
crate::fluent_generated::builtin_macros_asm_clobber_abi,

compiler/rustc_builtin_macros/src/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,10 @@ fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>)
395395
// These were a warning before #92959 and need to continue being that to avoid breaking
396396
// stable user code (#94508).
397397
Some(ast::ItemKind::MacCall(_)) => Level::Warning(None),
398-
_ => Level::Error { lint: false },
398+
_ => Level::Error,
399399
};
400400
let mut err = DiagnosticBuilder::<()>::new(dcx, level, msg);
401-
err.set_span(attr_sp);
401+
err.span(attr_sp);
402402
if let Some(item) = item {
403403
err.span_label(
404404
item.span,

compiler/rustc_codegen_gcc/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnabl
119119
fluent::codegen_gcc_target_feature_disable_or_enable
120120
);
121121
if let Some(span) = self.span {
122-
diag.set_span(span);
122+
diag.span(span);
123123
};
124124
if let Some(missing_features) = self.missing_features {
125125
diag.subdiagnostic(missing_features);
126126
}
127-
diag.set_arg("features", self.features.join(", "));
127+
diag.arg("features", self.features.join(", "));
128128
diag
129129
}
130130
}

compiler/rustc_codegen_llvm/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ fn report_inline_asm(
416416
cookie = 0;
417417
}
418418
let level = match level {
419-
llvm::DiagnosticLevel::Error => Level::Error { lint: false },
419+
llvm::DiagnosticLevel::Error => Level::Error,
420420
llvm::DiagnosticLevel::Warning => Level::Warning(None),
421421
llvm::DiagnosticLevel::Note | llvm::DiagnosticLevel::Remark => Level::Note,
422422
};

compiler/rustc_codegen_llvm/src/errors.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_
107107

108108
let mut diag =
109109
DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config);
110-
diag.set_arg("error", message);
110+
diag.arg("error", message);
111111
diag
112112
}
113113
}
@@ -130,12 +130,12 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnabl
130130
fluent::codegen_llvm_target_feature_disable_or_enable,
131131
);
132132
if let Some(span) = self.span {
133-
diag.set_span(span);
133+
diag.span(span);
134134
};
135135
if let Some(missing_features) = self.missing_features {
136136
diag.subdiagnostic(missing_features);
137137
}
138-
diag.set_arg("features", self.features.join(", "));
138+
diag.arg("features", self.features.join(", "));
139139
diag
140140
}
141141
}
@@ -205,8 +205,8 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for WithLlvmError<'_> {
205205
ParseBitcode => fluent::codegen_llvm_parse_bitcode_with_llvm_err,
206206
};
207207
let mut diag = self.0.into_diagnostic(dcx, level);
208-
diag.set_primary_message(msg_with_llvm_err);
209-
diag.set_arg("llvm_err", self.1);
208+
diag.primary_message(msg_with_llvm_err);
209+
diag.arg("llvm_err", self.1);
210210
diag
211211
}
212212
}

compiler/rustc_codegen_ssa/src/back/write.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1848,9 +1848,9 @@ impl SharedEmitterMain {
18481848
}
18491849
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
18501850
let err_level = match level {
1851-
Level::Error { lint: false } => rustc_errors::Level::Error { lint: false },
1852-
Level::Warning(_) => rustc_errors::Level::Warning(None),
1853-
Level::Note => rustc_errors::Level::Note,
1851+
Level::Error => Level::Error,
1852+
Level::Warning(_) => Level::Warning(None),
1853+
Level::Note => Level::Note,
18541854
_ => bug!("Invalid inline asm diagnostic level"),
18551855
};
18561856
let msg = msg.strip_prefix("error: ").unwrap_or(&msg).to_string();
@@ -1860,7 +1860,7 @@ impl SharedEmitterMain {
18601860
if cookie != 0 {
18611861
let pos = BytePos::from_u32(cookie);
18621862
let span = Span::with_root_ctxt(pos, pos);
1863-
err.set_span(span);
1863+
err.span(span);
18641864
};
18651865

18661866
// Point to the generated assembly if it is available.

compiler/rustc_codegen_ssa/src/errors.rs

+27-27
Original file line numberDiff line numberDiff line change
@@ -244,30 +244,30 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
244244
}
245245
thorin::Error::NamelessSection(_, offset) => {
246246
diag = build(fluent::codegen_ssa_thorin_section_without_name);
247-
diag.set_arg("offset", format!("0x{offset:08x}"));
247+
diag.arg("offset", format!("0x{offset:08x}"));
248248
diag
249249
}
250250
thorin::Error::RelocationWithInvalidSymbol(section, offset) => {
251251
diag = build(fluent::codegen_ssa_thorin_relocation_with_invalid_symbol);
252-
diag.set_arg("section", section);
253-
diag.set_arg("offset", format!("0x{offset:08x}"));
252+
diag.arg("section", section);
253+
diag.arg("offset", format!("0x{offset:08x}"));
254254
diag
255255
}
256256
thorin::Error::MultipleRelocations(section, offset) => {
257257
diag = build(fluent::codegen_ssa_thorin_multiple_relocations);
258-
diag.set_arg("section", section);
259-
diag.set_arg("offset", format!("0x{offset:08x}"));
258+
diag.arg("section", section);
259+
diag.arg("offset", format!("0x{offset:08x}"));
260260
diag
261261
}
262262
thorin::Error::UnsupportedRelocation(section, offset) => {
263263
diag = build(fluent::codegen_ssa_thorin_unsupported_relocation);
264-
diag.set_arg("section", section);
265-
diag.set_arg("offset", format!("0x{offset:08x}"));
264+
diag.arg("section", section);
265+
diag.arg("offset", format!("0x{offset:08x}"));
266266
diag
267267
}
268268
thorin::Error::MissingDwoName(id) => {
269269
diag = build(fluent::codegen_ssa_thorin_missing_dwo_name);
270-
diag.set_arg("id", format!("0x{id:08x}"));
270+
diag.arg("id", format!("0x{id:08x}"));
271271
diag
272272
}
273273
thorin::Error::NoCompilationUnits => {
@@ -284,7 +284,7 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
284284
}
285285
thorin::Error::MissingRequiredSection(section) => {
286286
diag = build(fluent::codegen_ssa_thorin_missing_required_section);
287-
diag.set_arg("section", section);
287+
diag.arg("section", section);
288288
diag
289289
}
290290
thorin::Error::ParseUnitAbbreviations(_) => {
@@ -305,34 +305,34 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
305305
}
306306
thorin::Error::IncompatibleIndexVersion(section, format, actual) => {
307307
diag = build(fluent::codegen_ssa_thorin_incompatible_index_version);
308-
diag.set_arg("section", section);
309-
diag.set_arg("actual", actual);
310-
diag.set_arg("format", format);
308+
diag.arg("section", section);
309+
diag.arg("actual", actual);
310+
diag.arg("format", format);
311311
diag
312312
}
313313
thorin::Error::OffsetAtIndex(_, index) => {
314314
diag = build(fluent::codegen_ssa_thorin_offset_at_index);
315-
diag.set_arg("index", index);
315+
diag.arg("index", index);
316316
diag
317317
}
318318
thorin::Error::StrAtOffset(_, offset) => {
319319
diag = build(fluent::codegen_ssa_thorin_str_at_offset);
320-
diag.set_arg("offset", format!("0x{offset:08x}"));
320+
diag.arg("offset", format!("0x{offset:08x}"));
321321
diag
322322
}
323323
thorin::Error::ParseIndex(_, section) => {
324324
diag = build(fluent::codegen_ssa_thorin_parse_index);
325-
diag.set_arg("section", section);
325+
diag.arg("section", section);
326326
diag
327327
}
328328
thorin::Error::UnitNotInIndex(unit) => {
329329
diag = build(fluent::codegen_ssa_thorin_unit_not_in_index);
330-
diag.set_arg("unit", format!("0x{unit:08x}"));
330+
diag.arg("unit", format!("0x{unit:08x}"));
331331
diag
332332
}
333333
thorin::Error::RowNotInIndex(_, row) => {
334334
diag = build(fluent::codegen_ssa_thorin_row_not_in_index);
335-
diag.set_arg("row", row);
335+
diag.arg("row", row);
336336
diag
337337
}
338338
thorin::Error::SectionNotInRow => {
@@ -341,7 +341,7 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
341341
}
342342
thorin::Error::EmptyUnit(unit) => {
343343
diag = build(fluent::codegen_ssa_thorin_empty_unit);
344-
diag.set_arg("unit", format!("0x{unit:08x}"));
344+
diag.arg("unit", format!("0x{unit:08x}"));
345345
diag
346346
}
347347
thorin::Error::MultipleDebugInfoSection => {
@@ -358,12 +358,12 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
358358
}
359359
thorin::Error::DuplicateUnit(unit) => {
360360
diag = build(fluent::codegen_ssa_thorin_duplicate_unit);
361-
diag.set_arg("unit", format!("0x{unit:08x}"));
361+
diag.arg("unit", format!("0x{unit:08x}"));
362362
diag
363363
}
364364
thorin::Error::MissingReferencedUnit(unit) => {
365365
diag = build(fluent::codegen_ssa_thorin_missing_referenced_unit);
366-
diag.set_arg("unit", format!("0x{unit:08x}"));
366+
diag.arg("unit", format!("0x{unit:08x}"));
367367
diag
368368
}
369369
thorin::Error::NoOutputObjectCreated => {
@@ -376,27 +376,27 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
376376
}
377377
thorin::Error::Io(e) => {
378378
diag = build(fluent::codegen_ssa_thorin_io);
379-
diag.set_arg("error", format!("{e}"));
379+
diag.arg("error", format!("{e}"));
380380
diag
381381
}
382382
thorin::Error::ObjectRead(e) => {
383383
diag = build(fluent::codegen_ssa_thorin_object_read);
384-
diag.set_arg("error", format!("{e}"));
384+
diag.arg("error", format!("{e}"));
385385
diag
386386
}
387387
thorin::Error::ObjectWrite(e) => {
388388
diag = build(fluent::codegen_ssa_thorin_object_write);
389-
diag.set_arg("error", format!("{e}"));
389+
diag.arg("error", format!("{e}"));
390390
diag
391391
}
392392
thorin::Error::GimliRead(e) => {
393393
diag = build(fluent::codegen_ssa_thorin_gimli_read);
394-
diag.set_arg("error", format!("{e}"));
394+
diag.arg("error", format!("{e}"));
395395
diag
396396
}
397397
thorin::Error::GimliWrite(e) => {
398398
diag = build(fluent::codegen_ssa_thorin_gimli_write);
399-
diag.set_arg("error", format!("{e}"));
399+
diag.arg("error", format!("{e}"));
400400
diag
401401
}
402402
_ => unimplemented!("Untranslated thorin error"),
@@ -414,8 +414,8 @@ pub struct LinkingFailed<'a> {
414414
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for LinkingFailed<'_> {
415415
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
416416
let mut diag = DiagnosticBuilder::new(dcx, level, fluent::codegen_ssa_linking_failed);
417-
diag.set_arg("linker_path", format!("{}", self.linker_path.display()));
418-
diag.set_arg("exit_status", format!("{}", self.exit_status));
417+
diag.arg("linker_path", format!("{}", self.linker_path.display()));
418+
diag.arg("exit_status", format!("{}", self.exit_status));
419419

420420
let contains_undefined_ref = self.escaped_output.contains("undefined reference to");
421421

0 commit comments

Comments
 (0)