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.
This commit is contained in:
Nicholas Nethercote
2024-01-09 09:08:49 +11:00
parent 2ea7a37e11
commit ed76b0b882
76 changed files with 296 additions and 293 deletions

View File

@@ -566,8 +566,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
E0044,
"foreign items may not have {kinds} parameters",
)
.span_label_mv(item.span, format!("can't have {kinds} parameters"))
.help_mv(
.with_span_label(item.span, format!("can't have {kinds} parameters"))
.with_help(
// FIXME: once we start storing spans for type arguments, turn this
// into a suggestion.
format!(
@@ -801,10 +801,9 @@ fn check_impl_items_against_trait<'tcx>(
};
tcx.dcx()
.struct_span_err(tcx.def_span(def_id), msg)
.note_mv(format!(
"specialization behaves in inconsistent and \
surprising ways with {feature}, \
and for now is disallowed"
.with_note(format!(
"specialization behaves in inconsistent and surprising ways with \
{feature}, and for now is disallowed"
))
.emit();
}
@@ -843,7 +842,7 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
let e = fields[FieldIdx::from_u32(0)].ty(tcx, args);
if !fields.iter().all(|f| f.ty(tcx, args) == e) {
struct_span_code_err!(tcx.dcx(), sp, E0076, "SIMD vector should be homogeneous")
.span_label_mv(sp, "SIMD elements must have the same type")
.with_span_label(sp, "SIMD elements must have the same type")
.emit();
return;
}
@@ -1120,7 +1119,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
E0084,
"unsupported representation for zero-variant enum"
)
.span_label_mv(tcx.def_span(def_id), "zero-variant enum")
.with_span_label(tcx.def_span(def_id), "zero-variant enum")
.emit();
}
}
@@ -1313,7 +1312,7 @@ pub(super) fn check_type_params_are_used<'tcx>(
"type parameter `{}` is unused",
param.name,
)
.span_label_mv(span, "unused type parameter")
.with_span_label(span, "unused type parameter")
.emit();
}
}

View File

@@ -934,12 +934,12 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
return_span,
"return type captures more lifetimes than trait definition",
)
.span_label_mv(self.tcx.def_span(def_id), "this lifetime was captured")
.span_note_mv(
.with_span_label(self.tcx.def_span(def_id), "this lifetime was captured")
.with_span_note(
self.tcx.def_span(self.def_id),
"hidden type must only reference lifetimes captured by this impl trait",
)
.note_mv(format!("hidden type inferred to be `{}`", self.ty))
.with_note(format!("hidden type inferred to be `{}`", self.ty))
.emit()
}
_ => self.tcx.dcx().delayed_bug("should've been able to remap region"),

View File

@@ -165,7 +165,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
"`Drop` impl requires `{root_predicate}` \
but the {self_descr} it is implemented for does not",
)
.span_note_mv(item_span, "the implementor must specify the same requirement")
.with_span_note(item_span, "the implementor must specify the same requirement")
.emit(),
);
}
@@ -197,7 +197,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
"`Drop` impl requires `{outlives}` \
but the {self_descr} it is implemented for does not",
)
.span_note_mv(item_span, "the implementor must specify the same requirement")
.with_span_note(item_span, "the implementor must specify the same requirement")
.emit(),
);
}

View File

@@ -30,7 +30,7 @@ fn equate_intrinsic_type<'tcx>(
}
_ => {
struct_span_code_err!(tcx.dcx(), it.span, E0622, "intrinsic must be a function")
.span_label_mv(it.span, "expected a function")
.with_span_label(it.span, "expected a function")
.emit();
return;
}

View File

@@ -156,7 +156,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
self.tcx
.dcx()
.struct_span_err(expr.span, msg)
.note_mv(
.with_note(
"only integers, floats, SIMD vectors, pointers and function pointers \
can be used as arguments for inline assembly",
)
@@ -171,7 +171,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
self.tcx
.dcx()
.struct_span_err(expr.span, msg)
.note_mv(format!("`{ty}` does not implement the Copy trait"))
.with_note(format!("`{ty}` does not implement the Copy trait"))
.emit();
}
@@ -191,11 +191,11 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
self.tcx
.dcx()
.struct_span_err(vec![in_expr.span, expr.span], msg)
.span_label_mv(in_expr.span, format!("type `{in_expr_ty}`"))
.span_label_mv(expr.span, format!("type `{ty}`"))
.note_mv(
.with_span_label(in_expr.span, format!("type `{in_expr_ty}`"))
.with_span_label(expr.span, format!("type `{ty}`"))
.with_note(
"asm inout arguments must have the same type, \
unless they are both pointers or integers of the same size",
unless they are both pointers or integers of the same size",
)
.emit();
}
@@ -242,7 +242,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
self.tcx
.dcx()
.struct_span_err(expr.span, msg)
.note_mv(format!(
.with_note(format!(
"this is required to use type `{}` with register class `{}`",
ty,
reg_class.name(),
@@ -459,11 +459,11 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
self.tcx
.dcx()
.struct_span_err(*op_sp, "invalid `sym` operand")
.span_label_mv(
.with_span_label(
self.tcx.def_span(anon_const.def_id),
format!("is {} `{}`", ty.kind().article(), ty),
)
.help_mv(
.with_help(
"`sym` operands must refer to either a function or a static",
)
.emit();

View File

@@ -202,8 +202,8 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
res = Err(tcx
.dcx()
.struct_span_err(sp, "impls of auto traits cannot be default")
.span_labels_mv(impl_.defaultness_span, "default because of this")
.span_label_mv(sp, "auto trait")
.with_span_labels(impl_.defaultness_span, "default because of this")
.with_span_label(sp, "auto trait")
.emit());
}
// We match on both `ty::ImplPolarity` and `ast::ImplPolarity` just to get the `!` span.
@@ -504,19 +504,18 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, trait_def_id: LocalDefId) {
gat_item_hir.span,
format!("missing required bound{} on `{}`", plural, gat_item_hir.ident),
)
.span_suggestion_mv(
.with_span_suggestion(
gat_item_hir.generics.tail_span_for_predicate_suggestion(),
format!("add the required where clause{plural}"),
suggestion,
Applicability::MachineApplicable,
)
.note_mv(format!(
.with_note(format!(
"{bound} currently required to ensure that impls have maximum flexibility"
))
.note_mv(
.with_note(
"we are soliciting feedback, see issue #87479 \
<https://github.com/rust-lang/rust/issues/87479> \
for more information",
<https://github.com/rust-lang/rust/issues/87479> for more information",
)
.emit();
}
@@ -839,8 +838,8 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem
trait_should_be_self,
"associated item referring to unboxed trait object for its own trait",
)
.span_label_mv(trait_name.span, "in this trait")
.multipart_suggestion_mv(
.with_span_label(trait_name.span, "in this trait")
.with_multipart_suggestion(
"you might have meant to use `Self` to refer to the implementing type",
sugg,
Applicability::MachineApplicable,
@@ -1600,7 +1599,7 @@ fn check_method_receiver<'tcx>(
the `arbitrary_self_types` feature",
),
)
.help_mv(HELP_FOR_SELF_TYPE)
.with_help(HELP_FOR_SELF_TYPE)
.emit()
} else {
// Report error; would not have worked with `arbitrary_self_types`.
@@ -1613,8 +1612,8 @@ fn check_method_receiver<'tcx>(
fn e0307(tcx: TyCtxt<'_>, span: Span, receiver_ty: Ty<'_>) -> ErrorGuaranteed {
struct_span_code_err!(tcx.dcx(), span, E0307, "invalid `self` parameter type: {receiver_ty}")
.note_mv("type of `self` must be `Self` or a type that dereferences to it")
.help_mv(HELP_FOR_SELF_TYPE)
.with_note("type of `self` must be `Self` or a type that dereferences to it")
.with_help(HELP_FOR_SELF_TYPE)
.emit()
}
@@ -1923,7 +1922,7 @@ fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalModDefId) -> Result<(), Error
fn error_392(tcx: TyCtxt<'_>, span: Span, param_name: Symbol) -> DiagnosticBuilder<'_> {
struct_span_code_err!(tcx.dcx(), span, E0392, "parameter `{param_name}` is never used")
.span_label_mv(span, "unused parameter")
.with_span_label(span, "unused parameter")
}
pub fn provide(providers: &mut Providers) {