Skip to content

Commit fd45d48

Browse files
committed
Ask compiler to use shim for rustc_nocopy_clone_marker types
1 parent 0ab52f0 commit fd45d48

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/librustc/traits/select.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,20 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21262126
}
21272127
}
21282128

2129-
ty::TyAdt(..) | ty::TyProjection(..) | ty::TyParam(..) | ty::TyAnon(..) => {
2129+
ty::TyAdt(adt, substs) => {
2130+
let attrs = self.tcx().get_attrs(adt.did);
2131+
if adt.is_enum() && attrs.iter().any(|a| a.check_name("rustc_nocopy_clone_marker")) {
2132+
// for Clone
2133+
let mut iter = substs.types()
2134+
.chain(adt.all_fields().map(|f| f.ty(self.tcx(), substs)));
2135+
Where(ty::Binder(iter.collect()))
2136+
} else {
2137+
// Fallback to whatever user-defined impls exist in this case.
2138+
None
2139+
}
2140+
}
2141+
2142+
ty::TyProjection(..) | ty::TyParam(..) | ty::TyAnon(..) => {
21302143
// Fallback to whatever user-defined impls exist in this case.
21312144
None
21322145
}

src/libsyntax_ext/deriving/clone.rs

Lines changed: 10 additions & 0 deletions
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)