Skip to content

Commit f58f1be

Browse files
committed
Ask compiler to use shim for rustc_nocopy_clone_marker types
1 parent 41e077a commit f58f1be

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/librustc/traits/select.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,27 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21502150
}
21512151
}
21522152

2153-
ty::TyAdt(..) | ty::TyProjection(..) | ty::TyParam(..) | ty::TyAnon(..) => {
2153+
ty::TyAdt(adt, substs) => {
2154+
let attrs = self.tcx().get_attrs(adt.did);
2155+
if adt.is_enum() && attrs.iter().any(|a| a.check_name("rustc_nocopy_clone_marker")) {
2156+
let trait_id = obligation.predicate.def_id();
2157+
if Some(trait_id) == self.tcx().lang_items().clone_trait() {
2158+
// for Clone
2159+
// this doesn't work for recursive types (FIXME(Manishearth))
2160+
// let mut iter = substs.types()
2161+
// .chain(adt.all_fields().map(|f| f.ty(self.tcx(), substs)));
2162+
let mut iter = substs.types();
2163+
Where(ty::Binder(iter.collect()))
2164+
} else {
2165+
None
2166+
}
2167+
} else {
2168+
// Fallback to whatever user-defined impls exist in this case.
2169+
None
2170+
}
2171+
}
2172+
2173+
ty::TyProjection(..) | ty::TyParam(..) | ty::TyAnon(..) => {
21542174
// Fallback to whatever user-defined impls exist in this case.
21552175
None
21562176
}

src/libsyntax_ext/deriving/clone.rs

+10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
5555
substructure = combine_substructure(Box::new(|c, s, sub| {
5656
cs_clone_shallow("Clone", c, s, sub, false)
5757
}));
58+
} else if attr::contains_name(&annitem.attrs, "rustc_nocopy_clone_marker") {
59+
if let ItemKind::Enum(..) = annitem.node {
60+
// Do nothing, this will be handled in a shim
61+
return
62+
}
63+
bounds = vec![];
64+
is_shallow = false;
65+
substructure = combine_substructure(Box::new(|c, s, sub| {
66+
cs_clone("Clone", c, s, sub)
67+
}));
5868
} else {
5969
bounds = vec![];
6070
is_shallow = false;

0 commit comments

Comments
 (0)