diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-01-09 09:08:49 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-01-10 07:40:00 +1100 |
| commit | ed76b0b882d0acff9295bcd76c2b119cf83e7219 (patch) | |
| tree | b40f6c489904d201833e5e446afbfbee1501e26a /compiler/rustc_hir_analysis/src | |
| parent | 2ea7a37e1113febac8603729e33fdd94f2738807 (diff) | |
| download | rust-ed76b0b882d0acff9295bcd76c2b119cf83e7219.tar.gz rust-ed76b0b882d0acff9295bcd76c2b119cf83e7219.zip | |
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.
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
15 files changed, 52 insertions, 54 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/bounds.rs b/compiler/rustc_hir_analysis/src/astconv/bounds.rs index 08de6701b3c..1f88aaa6a4b 100644 --- a/compiler/rustc_hir_analysis/src/astconv/bounds.rs +++ b/compiler/rustc_hir_analysis/src/astconv/bounds.rs @@ -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); diff --git a/compiler/rustc_hir_analysis/src/astconv/generics.rs b/compiler/rustc_hir_analysis/src/astconv/generics.rs index 93ac609eb3c..e2cd4d5f21c 100644 --- a/compiler/rustc_hir_analysis/src/astconv/generics.rs +++ b/compiler/rustc_hir_analysis/src/astconv/generics.rs @@ -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); diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index f8e76baaf7f..1f47564649e 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -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); diff --git a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs index 42538560cb8..ea2f5f50b5c 100644 --- a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs +++ b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs @@ -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(), ) diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index fee892d090c..6265ddafef0 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -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(); } } diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 9e8a2251665..469e7a6a13c 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -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"), diff --git a/compiler/rustc_hir_analysis/src/check/dropck.rs b/compiler/rustc_hir_analysis/src/check/dropck.rs index 47c6545f9f6..3275a81c3dd 100644 --- a/compiler/rustc_hir_analysis/src/check/dropck.rs +++ b/compiler/rustc_hir_analysis/src/check/dropck.rs @@ -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(), ); } diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 14cac1418ee..7c3e296dfce 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -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; } diff --git a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs index aadff6a97e3..db619d5169e 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs @@ -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(); diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index a5c5290e7bd..59c72227144 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -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) { diff --git a/compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs b/compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs index 77fdd20325a..4c3455c7240 100644 --- a/compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs +++ b/compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs @@ -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) => { diff --git a/compiler/rustc_hir_analysis/src/coherence/mod.rs b/compiler/rustc_hir_analysis/src/coherence/mod.rs index 0a7fe287a1f..561a254e89e 100644 --- a/compiler/rustc_hir_analysis/src/coherence/mod.rs +++ b/compiler/rustc_hir_analysis/src/coherence/mod.rs @@ -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 `{}`", diff --git a/compiler/rustc_hir_analysis/src/coherence/unsafety.rs b/compiler/rustc_hir_analysis/src/coherence/unsafety.rs index d82a6677777..7b146573a1b 100644 --- a/compiler/rustc_hir_analysis/src/coherence/unsafety.rs +++ b/compiler/rustc_hir_analysis/src/coherence/unsafety.rs @@ -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 ", diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index d41279e0615..3d8390d1946 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -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()); } diff --git a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs index 04c42b4b2e6..6657e3fd872 100644 --- a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs @@ -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. |
