Skip to content

Commit 4e04ccb

Browse files
committed
Revert "Try detecting mixed derive/derivative with Clone and Copy"
This reverts commit 4117fff. As of rust 1.17, proc-macros don't get attributes other than their own in the token stream they're fed. See rust-lang/rust#39572
1 parent 162742a commit 4e04ccb

File tree

5 files changed

+7
-77
lines changed

5 files changed

+7
-77
lines changed

src/attr.rs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,13 @@ pub struct InputClone {
4545
bounds: Option<Vec<syn::WherePredicate>>,
4646
/// Whether the implementation should have an explicit `clone_from`.
4747
pub clone_from: bool,
48-
/// Whether the `rustc_copy_clone_marker` was found.
49-
pub rustc_copy_clone_marker: bool,
5048
}
5149

5250
#[derive(Debug, Default)]
5351
/// Represent the `derivative(Clone(…))` attributes on an input.
5452
pub struct InputCopy {
5553
/// The `bound` attribute if present and the corresponding bounds.
5654
bounds: Option<Vec<syn::WherePredicate>>,
57-
/// Wether the input also derive `Clone` (ie. `derive(Clone)`, but not `derivative(Clone)`)
58-
derives_clone: bool,
5955
}
6056

6157
#[derive(Debug, Default)]
@@ -194,45 +190,21 @@ impl Input {
194190
for_all_attr! {
195191
for (name, values) in attrs;
196192
"Clone" => {
197-
let mut clone = input.clone.take().unwrap_or_default();
198-
199-
clone.rustc_copy_clone_marker = attrs
200-
.iter()
201-
.any(|attr| attr.value.name() == "rustc_copy_clone_marker");
202-
203193
match_attributes! {
194+
let Some(clone) = input.clone;
204195
for value in values;
205196
"bound" => try!(parse_bound(&mut clone.bounds, value)),
206197
"clone_from" => {
207198
clone.clone_from = try!(parse_boolean_meta_item(&value, true, "clone_from"));
208199
}
209200
}
210-
211-
input.clone = Some(clone);
212201
}
213202
"Copy" => {
214-
let mut copy = input.copy.take().unwrap_or_default();
215-
216-
for attr in attrs {
217-
if let syn::MetaItem::List(ref name, ref traits) = attr.value {
218-
fn is_clone(elem: &syn::NestedMetaItem) -> bool {
219-
match *elem {
220-
syn::NestedMetaItem::MetaItem(ref mi) => mi.name() == "Clone",
221-
syn::NestedMetaItem::Literal(..) => false,
222-
}
223-
}
224-
if name == "derive" && traits.iter().any(is_clone) {
225-
copy.derives_clone = true;
226-
}
227-
}
228-
}
229-
230203
match_attributes! {
204+
let Some(copy) = input.copy;
231205
for value in values;
232206
"bound" => try!(parse_bound(&mut copy.bounds, value)),
233207
}
234-
235-
input.copy = Some(copy);
236208
}
237209
"Debug" => {
238210
match_attributes! {
@@ -295,10 +267,6 @@ impl Input {
295267
self.copy.as_ref().map_or(None, |d| d.bounds.as_ref().map(Vec::as_slice))
296268
}
297269

298-
pub fn derives_clone(&self) -> bool {
299-
self.copy.as_ref().map_or(false, |d| d.derives_clone)
300-
}
301-
302270
pub fn debug_bound(&self) -> Option<&[syn::WherePredicate]> {
303271
self.debug.as_ref().map_or(None, |d| d.bounds.as_ref().map(Vec::as_slice))
304272
}
@@ -319,10 +287,6 @@ impl Input {
319287
self.hash.as_ref().map_or(None, |d| d.bounds.as_ref().map(Vec::as_slice))
320288
}
321289

322-
pub fn rustc_copy_clone_marker(&self) -> bool {
323-
self.clone.as_ref().map_or(false, |d| d.rustc_copy_clone_marker)
324-
}
325-
326290
pub fn partial_eq_bound(&self) -> Option<&[syn::WherePredicate]> {
327291
self.partial_eq.as_ref().map_or(None, |d| d.bounds.as_ref().map(Vec::as_slice))
328292
}

src/clone.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@ use syn::{self, aster};
66
use utils;
77

88
/// Derive `Copy` for `input`.
9-
pub fn derive_copy(input: &ast::Input) -> Result<quote::Tokens, String> {
9+
pub fn derive_copy(input: &ast::Input) -> quote::Tokens {
1010
let name = &input.ident;
1111

12-
if input.attrs.derives_clone() {
13-
return Err("`#[derivative(Copy)]` can't be used with `#[derive(Clone)]`".into());
14-
}
15-
1612
let copy_trait_path = copy_trait_path();
1713
let impl_generics = utils::build_impl_generics(
1814
input,
@@ -30,10 +26,10 @@ pub fn derive_copy(input: &ast::Input) -> Result<quote::Tokens, String> {
3026
.build()
3127
.build();
3228

33-
Ok(quote! {
29+
quote! {
3430
#[allow(unused_qualifications)]
3531
impl #impl_generics #copy_trait_path for #ty #where_clause {}
36-
})
32+
}
3733
}
3834

3935
/// Derive `Clone` for `input`.
@@ -57,8 +53,7 @@ pub fn derive_clone(input: &ast::Input) -> quote::Tokens {
5753
.build()
5854
.build();
5955

60-
let is_copy = input.attrs.rustc_copy_clone_marker() || input.attrs.copy.is_some();
61-
if is_copy && input.generics.ty_params.is_empty() {
56+
if input.attrs.copy.is_some() && input.generics.ty_params.is_empty() {
6257
quote! {
6358
#[allow(unused_qualifications)]
6459
impl #impl_generics #clone_trait_path for #ty #where_clause {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn derive_impls(input: &ast::Input) -> Result<quote::Tokens, String> {
2424
tokens.append(&clone::derive_clone(input).to_string());
2525
}
2626
if input.attrs.copy.is_some() {
27-
tokens.append(&try!(clone::derive_copy(input)).to_string());
27+
tokens.append(&clone::derive_copy(input).to_string());
2828
}
2929
if input.attrs.debug.is_some() {
3030
tokens.append(&debug::derive(input).to_string());

tests/compile-fail/derive-copy-clone.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/rustc-deriving-copyclone.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ struct OurOur1(Liar);
4444
#[derivative(Clone, Copy)]
4545
struct OurOur2(Liar);
4646

47-
#[derive(Copy)]
48-
#[derive(Derivative)]
49-
#[derivative(Clone)]
50-
struct TheirOur1(Liar);
51-
#[derive(Copy)]
52-
#[derive(Derivative)]
53-
#[derivative(Clone)]
54-
struct TheirOur2(Liar);
55-
5647
#[test]
5748
fn main() {
5849
let _ = TheirTheir(Liar).clone();
@@ -62,12 +53,4 @@ fn main() {
6253
assert!(!CLONED.load(Ordering::SeqCst), "OurOur1");
6354
let _ = OurOur2(Liar).clone();
6455
assert!(!CLONED.load(Ordering::SeqCst), "OurOur2");
65-
66-
// Ideally this would work the same, just testing that the behaviour does not change:
67-
CLONED.store(false, Ordering::SeqCst);
68-
let _ = TheirOur1(Liar).clone();
69-
assert!(CLONED.load(Ordering::SeqCst), "TheirOur1");
70-
CLONED.store(false, Ordering::SeqCst);
71-
let _ = TheirOur2(Liar).clone();
72-
assert!(CLONED.load(Ordering::SeqCst), "TheirOur2");
7356
}

0 commit comments

Comments
 (0)