Skip to content

Commit e7b6d0e

Browse files
committed
Rename consuming chaining methods on DiagnosticBuilder.
In #119606 I added them and used a `_mv` suffix, but that wasn't great. A `with_` prefix has three different existing uses. - Constructors, e.g. `Vec::with_capacity`. - Wrappers that provide an environment to execute some code, e.g. `with_session_globals`. - Consuming chaining methods, e.g. `Span::with_{lo,hi,ctxt}`. The third case is exactly what we want, so this commit changes `DiagnosticBuilder::foo_mv` to `DiagnosticBuilder::with_foo`. Thanks to @compiler-errors for the suggestion.
1 parent 8a34317 commit e7b6d0e

File tree

75 files changed

+298
-296
lines changed

Some content is hidden

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

75 files changed

+298
-296
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ macro_rules! gate {
2323
($visitor:expr, $feature:ident, $span:expr, $explain:expr, $help:expr) => {{
2424
if !$visitor.features.$feature && !$span.allows_unstable(sym::$feature) {
2525
feature_err(&$visitor.sess.parse_sess, sym::$feature, $span, $explain)
26-
.help_mv($help)
26+
.with_help($help)
2727
.emit();
2828
}
2929
}};

compiler/rustc_attr/src/session_diagnostics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ 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
DiagnosticBuilder::new(dcx, level, fluent::attr_unknown_meta_item)
58-
.span_mv(self.span)
59-
.code_mv(error_code!(E0541))
60-
.arg_mv("item", self.item)
61-
.arg_mv("expected", expected.join(", "))
62-
.span_label_mv(self.span, fluent::attr_label)
58+
.with_span(self.span)
59+
.with_code(error_code!(E0541))
60+
.with_arg("item", self.item)
61+
.with_arg("expected", expected.join(", "))
62+
.with_span_label(self.span, fluent::attr_label)
6363
}
6464
}
6565

compiler/rustc_borrowck/src/borrowck_errors.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
3838
"cannot use {} because it was mutably borrowed",
3939
desc,
4040
)
41-
.span_label_mv(borrow_span, format!("{borrow_desc} is borrowed here"))
42-
.span_label_mv(span, format!("use of borrowed {borrow_desc}"))
41+
.with_span_label(borrow_span, format!("{borrow_desc} is borrowed here"))
42+
.with_span_label(span, format!("use of borrowed {borrow_desc}"))
4343
}
4444

4545
pub(crate) fn cannot_mutably_borrow_multiply(
@@ -243,8 +243,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
243243
"cannot assign to {} because it is borrowed",
244244
desc,
245245
)
246-
.span_label_mv(borrow_span, format!("{desc} is borrowed here"))
247-
.span_label_mv(span, format!("{desc} is assigned to here but it was already borrowed"))
246+
.with_span_label(borrow_span, format!("{desc} is borrowed here"))
247+
.with_span_label(span, format!("{desc} is assigned to here but it was already borrowed"))
248248
}
249249

250250
pub(crate) fn cannot_reassign_immutable(
@@ -297,7 +297,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
297297
ty,
298298
type_name,
299299
)
300-
.span_label_mv(move_from_span, "cannot move out of here")
300+
.with_span_label(move_from_span, "cannot move out of here")
301301
}
302302

303303
pub(crate) fn cannot_move_out_of_interior_of_drop(
@@ -312,7 +312,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
312312
"cannot move out of type `{}`, which implements the `Drop` trait",
313313
container_ty,
314314
)
315-
.span_label_mv(move_from_span, "cannot move out of here")
315+
.with_span_label(move_from_span, "cannot move out of here")
316316
}
317317

318318
pub(crate) fn cannot_act_on_moved_value(
@@ -368,8 +368,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
368368
immutable_place,
369369
immutable_section,
370370
)
371-
.span_label_mv(mutate_span, format!("cannot {action}"))
372-
.span_label_mv(immutable_span, format!("value is immutable in {immutable_section}"))
371+
.with_span_label(mutate_span, format!("cannot {action}"))
372+
.with_span_label(immutable_span, format!("value is immutable in {immutable_section}"))
373373
}
374374

375375
pub(crate) fn cannot_borrow_across_coroutine_yield(
@@ -384,7 +384,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
384384
E0626,
385385
"borrow may still be in use when {coroutine_kind:#} yields",
386386
)
387-
.span_label_mv(yield_span, "possible yield occurs here")
387+
.with_span_label(yield_span, "possible yield occurs here")
388388
}
389389

390390
pub(crate) fn cannot_borrow_across_destructor(
@@ -423,7 +423,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
423423
REFERENCE = reference_desc,
424424
LOCAL = path_desc,
425425
)
426-
.span_label_mv(
426+
.with_span_label(
427427
span,
428428
format!("{return_kind}s a {reference_desc} data owned by the current function"),
429429
)
@@ -444,8 +444,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
444444
"{closure_kind} may outlive the current {scope}, but it borrows {borrowed_path}, \
445445
which is owned by the current {scope}",
446446
)
447-
.span_label_mv(capture_span, format!("{borrowed_path} is borrowed here"))
448-
.span_label_mv(closure_span, format!("may outlive borrowed value {borrowed_path}"))
447+
.with_span_label(capture_span, format!("{borrowed_path} is borrowed here"))
448+
.with_span_label(closure_span, format!("may outlive borrowed value {borrowed_path}"))
449449
}
450450

451451
pub(crate) fn thread_local_value_does_not_live_long_enough(

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2225,11 +2225,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22252225
);
22262226

22272227
self.thread_local_value_does_not_live_long_enough(borrow_span)
2228-
.span_label_mv(
2228+
.with_span_label(
22292229
borrow_span,
22302230
"thread-local variables cannot be borrowed beyond the end of the function",
22312231
)
2232-
.span_label_mv(drop_span, "end of enclosing function is here")
2232+
.with_span_label(drop_span, "end of enclosing function is here")
22332233
}
22342234

22352235
#[instrument(level = "debug", skip(self))]

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
334334
span,
335335
&format!("`{}` in pattern guard", self.local_names[local].unwrap()),
336336
)
337-
.note_mv(
337+
.with_note(
338338
"variables bound in patterns cannot be moved from \
339-
until after the end of the pattern guard",
339+
until after the end of the pattern guard",
340340
);
341341
} else if decl.is_ref_to_static() {
342342
return self.report_cannot_move_from_static(move_place, span);
@@ -382,8 +382,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
382382
);
383383

384384
self.cannot_move_out_of(span, &place_description)
385-
.span_label_mv(upvar_span, "captured outer variable")
386-
.span_label_mv(
385+
.with_span_label(upvar_span, "captured outer variable")
386+
.with_span_label(
387387
self.infcx.tcx.def_span(def_id),
388388
format!("captured by this `{closure_kind}` closure"),
389389
)

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ fn check_opaque_type_parameter_valid(
421421
return Err(tcx
422422
.dcx()
423423
.struct_span_err(span, "non-defining opaque type use in defining scope")
424-
.span_note_mv(spans, format!("{descr} used multiple times"))
424+
.with_span_note(spans, format!("{descr} used multiple times"))
425425
.emit());
426426
}
427427
}

compiler/rustc_builtin_macros/src/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
695695
let (sp, msg) = unused_operands.into_iter().next().unwrap();
696696
ecx.dcx()
697697
.struct_span_err(sp, msg)
698-
.span_label_mv(sp, msg)
699-
.help_mv(format!(
698+
.with_span_label(sp, msg)
699+
.with_help(format!(
700700
"if this argument is intentionally unused, \
701701
consider using it in an asm comment: `\"/*{help_str} */\"`"
702702
))

compiler/rustc_builtin_macros/src/errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,9 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for AsmClobberNoReg {
817817
level,
818818
crate::fluent_generated::builtin_macros_asm_clobber_no_reg,
819819
)
820-
.span_mv(self.spans.clone())
821-
.span_labels_mv(self.clobbers, &lbl1)
822-
.span_labels_mv(self.spans, &lbl2)
820+
.with_span(self.spans.clone())
821+
.with_span_labels(self.clobbers, &lbl1)
822+
.with_span_labels(self.spans, &lbl2)
823823
}
824824
}
825825

compiler/rustc_builtin_macros/src/proc_macro_harness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
194194

195195
self.dcx
196196
.struct_span_err(attr.span, msg)
197-
.span_label_mv(prev_attr.span, "previous attribute here")
197+
.with_span_label(prev_attr.span, "previous attribute here")
198198
.emit();
199199

200200
return;

compiler/rustc_builtin_macros/src/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>)
409409
),
410410
);
411411
}
412-
err.span_label_mv(attr_sp, "the `#[test]` macro causes a function to be run as a test and has no effect on non-functions")
413-
.span_suggestion_mv(attr_sp,
412+
err.with_span_label(attr_sp, "the `#[test]` macro causes a function to be run as a test and has no effect on non-functions")
413+
.with_span_suggestion(attr_sp,
414414
"replace with conditional compilation to make the item only exist when tests are being run",
415415
"#[cfg(test)]",
416416
Applicability::MaybeIncorrect)
@@ -480,7 +480,7 @@ fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
480480
"argument must be of the form: \
481481
`expected = \"error message\"`",
482482
)
483-
.note_mv(
483+
.with_note(
484484
"errors in this attribute were erroneously \
485485
allowed and will become a hard error in a \
486486
future release",

compiler/rustc_codegen_llvm/src/errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_
106106
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args());
107107

108108
DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)
109-
.arg_mv("error", message)
109+
.with_arg("error", message)
110110
}
111111
}
112112

@@ -204,8 +204,8 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for WithLlvmError<'_> {
204204
};
205205
self.0
206206
.into_diagnostic(dcx, level)
207-
.primary_message_mv(msg_with_llvm_err)
208-
.arg_mv("llvm_err", self.1)
207+
.with_primary_message(msg_with_llvm_err)
208+
.with_arg("llvm_err", self.1)
209209
}
210210
}
211211

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
309309
attr.span,
310310
"`#[target_feature(..)]` can only be applied to `unsafe` functions",
311311
)
312-
.span_label_mv(tcx.def_span(did), "not an `unsafe` function")
312+
.with_span_label(tcx.def_span(did), "not an `unsafe` function")
313313
.emit();
314314
} else {
315315
check_target_feature_trait_unsafe(tcx, did, attr.span);
@@ -478,7 +478,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
478478
InlineAttr::Never
479479
} else {
480480
struct_span_code_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument")
481-
.help_mv("valid inline arguments are `always` and `never`")
481+
.with_help("valid inline arguments are `always` and `never`")
482482
.emit();
483483

484484
InlineAttr::None
@@ -663,7 +663,7 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<u16> {
663663
let msg = format!("ordinal value in `link_ordinal` is too large: `{}`", &ordinal);
664664
tcx.dcx()
665665
.struct_span_err(attr.span, msg)
666-
.note_mv("the value may not exceed `u16::MAX`")
666+
.with_note("the value may not exceed `u16::MAX`")
667667
.emit();
668668
None
669669
}

compiler/rustc_codegen_ssa/src/errors.rs

+26-27
Original file line numberDiff line numberDiff line change
@@ -230,25 +230,25 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
230230
thorin::Error::DecompressData(_) => build(fluent::codegen_ssa_thorin_decompress_data),
231231
thorin::Error::NamelessSection(_, offset) => {
232232
build(fluent::codegen_ssa_thorin_section_without_name)
233-
.arg_mv("offset", format!("0x{offset:08x}"))
233+
.with_arg("offset", format!("0x{offset:08x}"))
234234
}
235235
thorin::Error::RelocationWithInvalidSymbol(section, offset) => {
236236
build(fluent::codegen_ssa_thorin_relocation_with_invalid_symbol)
237-
.arg_mv("section", section)
238-
.arg_mv("offset", format!("0x{offset:08x}"))
237+
.with_arg("section", section)
238+
.with_arg("offset", format!("0x{offset:08x}"))
239239
}
240240
thorin::Error::MultipleRelocations(section, offset) => {
241241
build(fluent::codegen_ssa_thorin_multiple_relocations)
242-
.arg_mv("section", section)
243-
.arg_mv("offset", format!("0x{offset:08x}"))
242+
.with_arg("section", section)
243+
.with_arg("offset", format!("0x{offset:08x}"))
244244
}
245245
thorin::Error::UnsupportedRelocation(section, offset) => {
246246
build(fluent::codegen_ssa_thorin_unsupported_relocation)
247-
.arg_mv("section", section)
248-
.arg_mv("offset", format!("0x{offset:08x}"))
247+
.with_arg("section", section)
248+
.with_arg("offset", format!("0x{offset:08x}"))
249249
}
250250
thorin::Error::MissingDwoName(id) => build(fluent::codegen_ssa_thorin_missing_dwo_name)
251-
.arg_mv("id", format!("0x{id:08x}")),
251+
.with_arg("id", format!("0x{id:08x}")),
252252
thorin::Error::NoCompilationUnits => {
253253
build(fluent::codegen_ssa_thorin_no_compilation_units)
254254
}
@@ -258,7 +258,7 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
258258
}
259259
thorin::Error::MissingRequiredSection(section) => {
260260
build(fluent::codegen_ssa_thorin_missing_required_section)
261-
.arg_mv("section", section)
261+
.with_arg("section", section)
262262
}
263263
thorin::Error::ParseUnitAbbreviations(_) => {
264264
build(fluent::codegen_ssa_thorin_parse_unit_abbreviations)
@@ -272,31 +272,30 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
272272
thorin::Error::ParseUnit(_) => build(fluent::codegen_ssa_thorin_parse_unit),
273273
thorin::Error::IncompatibleIndexVersion(section, format, actual) => {
274274
build(fluent::codegen_ssa_thorin_incompatible_index_version)
275-
.arg_mv("section", section)
276-
.arg_mv("actual", actual)
277-
.arg_mv("format", format)
275+
.with_arg("section", section)
276+
.with_arg("actual", actual)
277+
.with_arg("format", format)
278278
}
279279
thorin::Error::OffsetAtIndex(_, index) => {
280-
build(fluent::codegen_ssa_thorin_offset_at_index).arg_mv("index", index)
280+
build(fluent::codegen_ssa_thorin_offset_at_index).with_arg("index", index)
281281
}
282282
thorin::Error::StrAtOffset(_, offset) => {
283283
build(fluent::codegen_ssa_thorin_str_at_offset)
284-
.arg_mv("offset", format!("0x{offset:08x}"))
284+
.with_arg("offset", format!("0x{offset:08x}"))
285285
}
286286
thorin::Error::ParseIndex(_, section) => {
287-
build(fluent::codegen_ssa_thorin_parse_index).arg_mv("section", section)
287+
build(fluent::codegen_ssa_thorin_parse_index).with_arg("section", section)
288288
}
289289
thorin::Error::UnitNotInIndex(unit) => {
290290
build(fluent::codegen_ssa_thorin_unit_not_in_index)
291-
.arg_mv("unit", format!("0x{unit:08x}"))
291+
.with_arg("unit", format!("0x{unit:08x}"))
292292
}
293293
thorin::Error::RowNotInIndex(_, row) => {
294-
build(fluent::codegen_ssa_thorin_row_not_in_index).arg_mv("row", row)
294+
build(fluent::codegen_ssa_thorin_row_not_in_index).with_arg("row", row)
295295
}
296296
thorin::Error::SectionNotInRow => build(fluent::codegen_ssa_thorin_section_not_in_row),
297-
thorin::Error::EmptyUnit(unit) => {
298-
build(fluent::codegen_ssa_thorin_empty_unit).arg_mv("unit", format!("0x{unit:08x}"))
299-
}
297+
thorin::Error::EmptyUnit(unit) => build(fluent::codegen_ssa_thorin_empty_unit)
298+
.with_arg("unit", format!("0x{unit:08x}")),
300299
thorin::Error::MultipleDebugInfoSection => {
301300
build(fluent::codegen_ssa_thorin_multiple_debug_info_section)
302301
}
@@ -305,10 +304,10 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
305304
}
306305
thorin::Error::NotSplitUnit => build(fluent::codegen_ssa_thorin_not_split_unit),
307306
thorin::Error::DuplicateUnit(unit) => build(fluent::codegen_ssa_thorin_duplicate_unit)
308-
.arg_mv("unit", format!("0x{unit:08x}")),
307+
.with_arg("unit", format!("0x{unit:08x}")),
309308
thorin::Error::MissingReferencedUnit(unit) => {
310309
build(fluent::codegen_ssa_thorin_missing_referenced_unit)
311-
.arg_mv("unit", format!("0x{unit:08x}"))
310+
.with_arg("unit", format!("0x{unit:08x}"))
312311
}
313312
thorin::Error::NoOutputObjectCreated => {
314313
build(fluent::codegen_ssa_thorin_not_output_object_created)
@@ -317,19 +316,19 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
317316
build(fluent::codegen_ssa_thorin_mixed_input_encodings)
318317
}
319318
thorin::Error::Io(e) => {
320-
build(fluent::codegen_ssa_thorin_io).arg_mv("error", format!("{e}"))
319+
build(fluent::codegen_ssa_thorin_io).with_arg("error", format!("{e}"))
321320
}
322321
thorin::Error::ObjectRead(e) => {
323-
build(fluent::codegen_ssa_thorin_object_read).arg_mv("error", format!("{e}"))
322+
build(fluent::codegen_ssa_thorin_object_read).with_arg("error", format!("{e}"))
324323
}
325324
thorin::Error::ObjectWrite(e) => {
326-
build(fluent::codegen_ssa_thorin_object_write).arg_mv("error", format!("{e}"))
325+
build(fluent::codegen_ssa_thorin_object_write).with_arg("error", format!("{e}"))
327326
}
328327
thorin::Error::GimliRead(e) => {
329-
build(fluent::codegen_ssa_thorin_gimli_read).arg_mv("error", format!("{e}"))
328+
build(fluent::codegen_ssa_thorin_gimli_read).with_arg("error", format!("{e}"))
330329
}
331330
thorin::Error::GimliWrite(e) => {
332-
build(fluent::codegen_ssa_thorin_gimli_write).arg_mv("error", format!("{e}"))
331+
build(fluent::codegen_ssa_thorin_gimli_write).with_arg("error", format!("{e}"))
333332
}
334333
_ => unimplemented!("Untranslated thorin error"),
335334
}

compiler/rustc_codegen_ssa/src/target_features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn from_target_feature(
2727
let code = "enable = \"..\"";
2828
tcx.dcx()
2929
.struct_span_err(span, msg)
30-
.span_suggestion_mv(span, "must be of the form", code, Applicability::HasPlaceholders)
30+
.with_span_suggestion(span, "must be of the form", code, Applicability::HasPlaceholders)
3131
.emit();
3232
};
3333
let rust_features = tcx.features();

0 commit comments

Comments
 (0)