Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ed76b0b

Browse files
committed
Rename consuming chaining methods on DiagnosticBuilder.
In rust-lang#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 2ea7a37 commit ed76b0b

File tree

76 files changed

+296
-293
lines changed

Some content is hidden

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

76 files changed

+296
-293
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 12 additions & 12 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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",

0 commit comments

Comments
 (0)