diff --git a/compiler/rustc_trait_selection/src/traits/misc.rs b/compiler/rustc_trait_selection/src/traits/misc.rs index b83b0bf1ca52e..f04f527ccb7af 100644 --- a/compiler/rustc_trait_selection/src/traits/misc.rs +++ b/compiler/rustc_trait_selection/src/traits/misc.rs @@ -20,7 +20,7 @@ pub fn can_type_implement_copy<'tcx>( tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, self_type: Ty<'tcx>, - cause: ObligationCause<'tcx>, + parent_cause: ObligationCause<'tcx>, ) -> Result<(), CopyImplementationError<'tcx>> { // FIXME: (@jroesch) float this code up tcx.infer_ctxt().enter(|infcx| { @@ -59,7 +59,7 @@ pub fn can_type_implement_copy<'tcx>( .ty(tcx, traits::InternalSubsts::identity_for_item(tcx, adt.did())) .has_param_types_or_consts() { - cause.clone() + parent_cause.clone() } else { ObligationCause::dummy_with_span(span) }; diff --git a/compiler/rustc_typeck/src/coherence/builtin.rs b/compiler/rustc_typeck/src/coherence/builtin.rs index c809b8bdd73db..9f4e6a46d7322 100644 --- a/compiler/rustc_typeck/src/coherence/builtin.rs +++ b/compiler/rustc_typeck/src/coherence/builtin.rs @@ -107,6 +107,10 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) { for (field, ty) in fields { let field_span = tcx.def_span(field.did); + let field_ty_span = match tcx.hir().get_if_local(field.did) { + Some(hir::Node::Field(field_def)) => field_def.ty.span, + _ => field_span, + }; err.span_label(field_span, "this field does not implement `Copy`"); // Spin up a new FulfillmentContext, so we can get the _precise_ reason // why this field does not implement Copy. This is useful because sometimes @@ -119,7 +123,7 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) { param_env, ty, tcx.lang_items().copy_trait().unwrap(), - traits::ObligationCause::dummy_with_span(field_span), + traits::ObligationCause::dummy_with_span(field_ty_span), ); for error in fulfill_cx.select_all_or_error(&infcx) { let error_predicate = error.obligation.predicate; diff --git a/src/test/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr b/src/test/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr index 4eb1e318d97c3..faf730a5ce321 100644 --- a/src/test/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr +++ b/src/test/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr @@ -10,12 +10,12 @@ LL | pub size: Vector2 | -------------------- this field does not implement `Copy` | note: the `Copy` impl for `Vector2` requires that `K: Debug` - --> $DIR/missing-bound-in-derive-copy-impl-3.rs:12:5 + --> $DIR/missing-bound-in-derive-copy-impl-3.rs:12:14 | LL | pub loc: Vector2, - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ LL | pub size: Vector2 - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting this bound | diff --git a/src/test/ui/suggestions/missing-bound-in-derive-copy-impl.stderr b/src/test/ui/suggestions/missing-bound-in-derive-copy-impl.stderr index 1cf2ab95bc3a8..11bc540991775 100644 --- a/src/test/ui/suggestions/missing-bound-in-derive-copy-impl.stderr +++ b/src/test/ui/suggestions/missing-bound-in-derive-copy-impl.stderr @@ -10,12 +10,12 @@ LL | pub size: Vector2 | -------------------- this field does not implement `Copy` | note: the `Copy` impl for `Vector2` requires that `K: Debug` - --> $DIR/missing-bound-in-derive-copy-impl.rs:11:5 + --> $DIR/missing-bound-in-derive-copy-impl.rs:11:14 | LL | pub loc: Vector2, - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ LL | pub size: Vector2 - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `K` | diff --git a/src/test/ui/union/union-copy.stderr b/src/test/ui/union/union-copy.stderr index 279808dd55bb4..8ecdafdde2045 100644 --- a/src/test/ui/union/union-copy.stderr +++ b/src/test/ui/union/union-copy.stderr @@ -8,10 +8,10 @@ LL | impl Copy for W {} | ^^^^ | note: the `Copy` impl for `ManuallyDrop` requires that `String: Copy` - --> $DIR/union-copy.rs:8:5 + --> $DIR/union-copy.rs:8:8 | LL | a: std::mem::ManuallyDrop - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error