Skip to content

Commit 2c33d2f

Browse files
committed
Pass down the self def id instead of the type
1 parent 9898cff commit 2c33d2f

File tree

7 files changed

+35
-19
lines changed

7 files changed

+35
-19
lines changed

src/librustc/ich/impls_ty.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,11 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::InstanceDef<'gcx> {
761761
ty::InstanceDef::CloneCopyShim(def_id) => {
762762
def_id.hash_stable(hcx, hasher);
763763
}
764-
ty::InstanceDef::CloneStructuralShim(def_id, t) |
765-
ty::InstanceDef::CloneNominalShim(def_id, t) => {
764+
ty::InstanceDef::CloneNominalShim { clone, ty } => {
765+
clone.hash_stable(hcx, hasher);
766+
ty.hash_stable(hcx, hasher);
767+
}
768+
ty::InstanceDef::CloneStructuralShim(def_id, t) => {
766769
def_id.hash_stable(hcx, hasher);
767770
t.hash_stable(hcx, hasher);
768771
}

src/librustc/ty/instance.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ pub enum InstanceDef<'tcx> {
5353
/// The DefId is the DefId of the Clone::clone function
5454
CloneStructuralShim(DefId, Ty<'tcx>),
5555
///`<T as Clone>::clone` shim for closures
56-
///
57-
/// The DefId is the DefId of the Clone::clone function
58-
CloneNominalShim(DefId, Ty<'tcx>),
56+
CloneNominalShim {
57+
/// The DefId of the Clone::clone trait method def
58+
clone: DefId,
59+
/// The DefId of the self type
60+
ty: DefId
61+
},
5962
}
6063

6164
impl<'a, 'tcx> Instance<'tcx> {
@@ -80,7 +83,7 @@ impl<'tcx> InstanceDef<'tcx> {
8083
InstanceDef::DropGlue(def_id, _) |
8184
InstanceDef::CloneCopyShim(def_id) |
8285
InstanceDef::CloneStructuralShim(def_id, _) |
83-
InstanceDef::CloneNominalShim(def_id, _) => def_id
86+
InstanceDef::CloneNominalShim{ clone: def_id, ..} => def_id
8487
}
8588
}
8689

@@ -146,11 +149,11 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
146149
InstanceDef::DropGlue(_, ty) => {
147150
write!(f, " - shim({:?})", ty)
148151
}
149-
InstanceDef::CloneCopyShim(def) => {
152+
InstanceDef::CloneCopyShim(def) |
153+
InstanceDef::CloneNominalShim { ty: def, ..} => {
150154
write!(f, " - shim({:?})", def)
151155
}
152-
InstanceDef::CloneStructuralShim(_, ty) |
153-
InstanceDef::CloneNominalShim(_, ty) => {
156+
InstanceDef::CloneStructuralShim(_, ty) => {
154157
write!(f, " - shim({:?})", ty)
155158
}
156159
}
@@ -308,6 +311,7 @@ fn resolve_associated_item<'a, 'tcx>(
308311
}
309312
traits::VtableBuiltin(..) => {
310313
if let Some(_) = tcx.lang_items().clone_trait() {
314+
let mut substs = rcvr_substs;
311315
let name = tcx.item_name(def_id);
312316
let def = if name == "clone" {
313317
let self_ty = trait_ref.self_ty();
@@ -317,15 +321,21 @@ fn resolve_associated_item<'a, 'tcx>(
317321
}
318322
ty::TyArray(..) => ty::InstanceDef::CloneStructuralShim(def_id, self_ty),
319323
ty::TyTuple(..) => ty::InstanceDef::CloneStructuralShim(def_id, self_ty),
320-
ty::TyClosure(..) => ty::InstanceDef::CloneNominalShim(def_id, self_ty),
324+
ty::TyClosure(ty_did, closure_substs) => {
325+
substs = closure_substs.substs;
326+
ty::InstanceDef::CloneNominalShim {
327+
clone: def_id,
328+
ty: ty_did
329+
}
330+
}
321331
_ => unreachable!("Type {:?} does not have clone shims", self_ty)
322332
}
323333
} else {
324334
ty::InstanceDef::Item(def_id)
325335
};
326336
Some(Instance {
327337
def,
328-
substs: rcvr_substs
338+
substs
329339
})
330340
} else {
331341
None

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23532353
ty::InstanceDef::DropGlue(..) |
23542354
ty::InstanceDef::CloneCopyShim(..) |
23552355
ty::InstanceDef::CloneStructuralShim(..) |
2356-
ty::InstanceDef::CloneNominalShim(..) => {
2356+
ty::InstanceDef::CloneNominalShim { .. } => {
23572357
self.mir_shims(instance)
23582358
}
23592359
}

src/librustc_mir/interpret/terminator/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
297297
ty::InstanceDef::DropGlue(..) |
298298
ty::InstanceDef::CloneCopyShim(..) |
299299
ty::InstanceDef::CloneStructuralShim(..) |
300-
ty::InstanceDef::CloneNominalShim(..) |
300+
ty::InstanceDef::CloneNominalShim { .. } |
301301
ty::InstanceDef::Item(_) => {
302302
// Push the stack frame, and potentially be entirely done if the call got hooked
303303
if M::eval_fn_call(self, instance, destination, args, span, sig)? {

src/librustc_mir/monomorphize/collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ fn visit_instance_use<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
713713
ty::InstanceDef::FnPtrShim(..) |
714714
ty::InstanceDef::CloneCopyShim(..) |
715715
ty::InstanceDef::CloneStructuralShim(..) |
716-
ty::InstanceDef::CloneNominalShim(..) => {
716+
ty::InstanceDef::CloneNominalShim { .. } => {
717717
output.push(create_fn_mono_item(instance));
718718
}
719719
}
@@ -733,7 +733,7 @@ fn should_monomorphize_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance:
733733
ty::InstanceDef::Intrinsic(_) |
734734
ty::InstanceDef::CloneCopyShim(..) |
735735
ty::InstanceDef::CloneStructuralShim(..) |
736-
ty::InstanceDef::CloneNominalShim(..) => return true
736+
ty::InstanceDef::CloneNominalShim { .. } => return true
737737
};
738738
match tcx.hir.get_if_local(def_id) {
739739
Some(hir_map::NodeForeignItem(..)) => {

src/librustc_mir/monomorphize/partitioning.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub trait CodegenUnitExt<'tcx> {
177177
InstanceDef::DropGlue(..) |
178178
InstanceDef::CloneCopyShim(..) |
179179
InstanceDef::CloneStructuralShim(..) |
180-
InstanceDef::CloneNominalShim(..) => {
180+
InstanceDef::CloneNominalShim { .. } => {
181181
None
182182
}
183183
}
@@ -380,7 +380,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
380380
InstanceDef::DropGlue(..) |
381381
InstanceDef::CloneCopyShim(..) |
382382
InstanceDef::CloneStructuralShim(..) |
383-
InstanceDef::CloneNominalShim(..) => {
383+
InstanceDef::CloneNominalShim { .. } => {
384384
Visibility::Hidden
385385
}
386386
};
@@ -625,7 +625,7 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
625625
ty::InstanceDef::Virtual(..) |
626626
ty::InstanceDef::CloneCopyShim(..) |
627627
ty::InstanceDef::CloneStructuralShim(..) |
628-
ty::InstanceDef::CloneNominalShim(..) => return None
628+
ty::InstanceDef::CloneNominalShim { .. } => return None
629629
};
630630

631631
// If this is a method, we want to put it into the same module as

src/librustc_mir/shim.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ fn make_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
106106
builder.copy_shim();
107107
builder.into_mir()
108108
}
109-
ty::InstanceDef::CloneNominalShim(def_id, ty) |
109+
ty::InstanceDef::CloneNominalShim { clone, ty } => {
110+
let ty = tcx.type_of(ty);
111+
build_clone_shim(tcx, clone, ty)
112+
}
110113
ty::InstanceDef::CloneStructuralShim(def_id, ty) => {
111114
build_clone_shim(tcx, def_id, ty)
112115
}

0 commit comments

Comments
 (0)