Closed
Description
This:
macro_rules! define_vec (
() => (
mod foo {
#[deriving(Eq)]
pub struct bar;
}
)
)
define_vec!()
fn main() {}
...doesn't compile:
moon.rs:4:23: 4:25 error: conflicting implementations for a trait
moon.rs:4 #[deriving(Eq)]
^~
moon.rs:4:23: 4:25 note: note conflicting implementation here
moon.rs:4 #[deriving(Eq)]
^~
moon.rs:4:23: 4:25 error: conflicting implementations for a trait
moon.rs:4 #[deriving(Eq)]
^~
moon.rs:4:23: 4:25 note: note conflicting implementation here
moon.rs:4 #[deriving(Eq)]
^~
error: aborting due to 2 previous errors
Taking a look at the expanded code:
mod foo {
#[deriving(Eq)]
pub struct bar;
#[doc = "Automatically derived."]
pub impl ::std::cmp::Eq for bar {
pub fn eq(&self, __arg_0: &bar) -> ::bool {
match *__arg_0 { bar => match *self { bar => true } }
}
pub fn ne(&self, __arg_0: &bar) -> ::bool {
match *__arg_0 { bar => match *self { bar => false } }
}
}
#[doc = "Automatically derived."]
pub impl ::std::cmp::Eq for bar {
pub fn eq(&self, __arg_0: &bar) -> ::bool {
match *__arg_0 { bar => match *self { bar => true } }
}
pub fn ne(&self, __arg_0: &bar) -> ::bool {
match *__arg_0 { bar => match *self { bar => false } }
}
}
}
fn main() { }
Notice that it's generating a second identical impl for the given trait. I've tested that this happens with both Eq
and ToStr
, so I presume it applies to the deriving code in general.