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:
parent
2ea7a37e11
commit
ed76b0b882
76 changed files with 296 additions and 293 deletions
|
@ -305,7 +305,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
|||
binding.span,
|
||||
format!("{} `{}` is private", assoc_item.kind, binding.item_name),
|
||||
)
|
||||
.span_label_mv(binding.span, format!("private {}", assoc_item.kind))
|
||||
.with_span_label(binding.span, format!("private {}", assoc_item.kind))
|
||||
.emit();
|
||||
}
|
||||
tcx.check_stability(assoc_item.def_id, Some(hir_ref_id), binding.span, None);
|
||||
|
|
|
@ -70,7 +70,7 @@ fn generic_arg_mismatch_err(
|
|||
Res::Err => {
|
||||
add_braces_suggestion(arg, &mut err);
|
||||
return err
|
||||
.primary_message_mv("unresolved item provided when a constant was expected")
|
||||
.with_primary_message("unresolved item provided when a constant was expected")
|
||||
.emit();
|
||||
}
|
||||
Res::Def(DefKind::TyParam, src_def_id) => {
|
||||
|
@ -651,7 +651,7 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
|
|||
&& args.num_lifetime_params() != param_counts.lifetimes
|
||||
{
|
||||
struct_span_code_err!(tcx.dcx(), span, E0794, "{}", msg)
|
||||
.span_note_mv(span_late, note)
|
||||
.with_span_note(span_late, note)
|
||||
.emit();
|
||||
} else {
|
||||
let mut multispan = MultiSpan::from_span(span);
|
||||
|
|
|
@ -1618,9 +1618,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let def_span = tcx.def_span(item);
|
||||
tcx.dcx()
|
||||
.struct_span_err(span, msg)
|
||||
.code_mv(rustc_errors::error_code!(E0624))
|
||||
.span_label_mv(span, format!("private {kind}"))
|
||||
.span_label_mv(def_span, format!("{kind} defined here"))
|
||||
.with_code(rustc_errors::error_code!(E0624))
|
||||
.with_span_label(span, format!("private {kind}"))
|
||||
.with_span_label(def_span, format!("{kind} defined here"))
|
||||
.emit();
|
||||
}
|
||||
tcx.check_stability(item, Some(block), span, None);
|
||||
|
|
|
@ -298,7 +298,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
tcx.def_descr(def_id),
|
||||
tcx.item_name(def_id),
|
||||
)
|
||||
.note_mv(
|
||||
.with_note(
|
||||
rustc_middle::traits::ObjectSafetyViolation::SupertraitSelf(smallvec![])
|
||||
.error_msg(),
|
||||
)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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(),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -77,8 +77,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
|
|||
"duplicate definitions with name `{}`",
|
||||
ident,
|
||||
)
|
||||
.span_label_mv(span, format!("duplicate definitions for `{ident}`"))
|
||||
.span_label_mv(*former, format!("other definition for `{ident}`"))
|
||||
.with_span_label(span, format!("duplicate definitions for `{ident}`"))
|
||||
.with_span_label(*former, format!("other definition for `{ident}`"))
|
||||
.emit();
|
||||
}
|
||||
Entry::Vacant(entry) => {
|
||||
|
|
|
@ -181,7 +181,7 @@ fn check_object_overlap<'tcx>(
|
|||
trait_ref.self_ty(),
|
||||
tcx.def_path_str(trait_def_id)
|
||||
)
|
||||
.span_label_mv(
|
||||
.with_span_label(
|
||||
span,
|
||||
format!(
|
||||
"`{}` automatically implements trait `{}`",
|
||||
|
|
|
@ -25,7 +25,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
"implementing the trait `{}` is not unsafe",
|
||||
trait_ref.print_trait_sugared()
|
||||
)
|
||||
.span_suggestion_verbose_mv(
|
||||
.with_span_suggestion_verbose(
|
||||
item.span.with_hi(item.span.lo() + rustc_span::BytePos(7)),
|
||||
"remove `unsafe` from this trait implementation",
|
||||
"",
|
||||
|
@ -42,13 +42,13 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
"the trait `{}` requires an `unsafe impl` declaration",
|
||||
trait_ref.print_trait_sugared()
|
||||
)
|
||||
.note_mv(format!(
|
||||
.with_note(format!(
|
||||
"the trait `{}` enforces invariants that the compiler can't check. \
|
||||
Review the trait documentation and make sure this implementation \
|
||||
upholds those invariants before adding the `unsafe` keyword",
|
||||
trait_ref.print_trait_sugared()
|
||||
))
|
||||
.span_suggestion_verbose_mv(
|
||||
.with_span_suggestion_verbose(
|
||||
item.span.shrink_to_lo(),
|
||||
"add `unsafe` to this trait implementation",
|
||||
"unsafe ",
|
||||
|
@ -65,13 +65,13 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
"requires an `unsafe impl` declaration due to `#[{}]` attribute",
|
||||
attr_name
|
||||
)
|
||||
.note_mv(format!(
|
||||
.with_note(format!(
|
||||
"the trait `{}` enforces invariants that the compiler can't check. \
|
||||
Review the trait documentation and make sure this implementation \
|
||||
upholds those invariants before adding the `unsafe` keyword",
|
||||
trait_ref.print_trait_sugared()
|
||||
))
|
||||
.span_suggestion_verbose_mv(
|
||||
.with_span_suggestion_verbose(
|
||||
item.span.shrink_to_lo(),
|
||||
"add `unsafe` to this trait implementation",
|
||||
"unsafe ",
|
||||
|
|
|
@ -751,7 +751,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||
lifetime.ident.span,
|
||||
"higher kinded lifetime bounds on nested opaque types are not supported yet",
|
||||
)
|
||||
.span_note_mv(self.tcx.def_span(def_id), "lifetime declared here")
|
||||
.with_span_note(self.tcx.def_span(def_id), "lifetime declared here")
|
||||
.emit();
|
||||
self.uninsert_lifetime_on_error(lifetime, def.unwrap());
|
||||
}
|
||||
|
|
|
@ -523,7 +523,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
fn start_diagnostics(&self) -> DiagnosticBuilder<'tcx> {
|
||||
let span = self.path_segment.ident.span;
|
||||
let msg = self.create_error_message();
|
||||
self.tcx.dcx().struct_span_err(span, msg).code_mv(self.code())
|
||||
self.tcx.dcx().struct_span_err(span, msg).with_code(self.code())
|
||||
}
|
||||
|
||||
/// Builds the `expected 1 type argument / supplied 2 type arguments` message.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue