Preserve span on Derive trait impls
diff --git a/syntax/derive.rs b/syntax/derive.rs
index 855e80f..501dd61 100644
--- a/syntax/derive.rs
+++ b/syntax/derive.rs
@@ -1,17 +1,31 @@
-use proc_macro2::Ident;
+use proc_macro2::{Ident, Span};
+
+#[derive(Copy, Clone)]
+pub struct Derive {
+ pub what: Trait,
+ pub span: Span,
+}
#[derive(Copy, Clone, PartialEq)]
-pub enum Derive {
+pub enum Trait {
Clone,
Copy,
}
impl Derive {
pub fn from(ident: &Ident) -> Option<Self> {
- match ident.to_string().as_str() {
- "Clone" => Some(Derive::Clone),
- "Copy" => Some(Derive::Copy),
- _ => None,
- }
+ let what = match ident.to_string().as_str() {
+ "Clone" => Trait::Clone,
+ "Copy" => Trait::Copy,
+ _ => return None,
+ };
+ let span = ident.span();
+ Some(Derive { what, span })
+ }
+}
+
+impl PartialEq<Trait> for Derive {
+ fn eq(&self, other: &Trait) -> bool {
+ self.what == *other
}
}