Tighten spans for bad fields in Copy struct
This commit is contained in:
parent
a6b8c69548
commit
4c6a6bc3f9
@ -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)
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -10,12 +10,12 @@ LL | pub size: Vector2<K>
|
||||
| -------------------- this field does not implement `Copy`
|
||||
|
|
||||
note: the `Copy` impl for `Vector2<K>` 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<K>,
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^
|
||||
LL | pub size: Vector2<K>
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^
|
||||
= 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
|
||||
|
|
||||
|
@ -10,12 +10,12 @@ LL | pub size: Vector2<K>
|
||||
| -------------------- this field does not implement `Copy`
|
||||
|
|
||||
note: the `Copy` impl for `Vector2<K>` 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<K>,
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^
|
||||
LL | pub size: Vector2<K>
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^
|
||||
= 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`
|
||||
|
|
||||
|
@ -8,10 +8,10 @@ LL | impl Copy for W {}
|
||||
| ^^^^
|
||||
|
|
||||
note: the `Copy` impl for `ManuallyDrop<String>` requires that `String: Copy`
|
||||
--> $DIR/union-copy.rs:8:5
|
||||
--> $DIR/union-copy.rs:8:8
|
||||
|
|
||||
LL | a: std::mem::ManuallyDrop<String>
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user