Closed
Description
This obviously fails to compile:
struct X;
impl X {
fn f(&self) {}
}
impl X {
fn f(&self) {}
}
error[E0592]: duplicate definitions with name `f`
--> a.rs:3:4
|
3 | fn f(&self) {}
| ^^^^^^^^^^^^^^ duplicate definitions for `f`
...
6 | fn f(&self) {}
| -------------- other definition for `f`
But this does not:
struct X;
impl X {
fn f(&self) {}
}
macro_rules! do_impl {
($name: ident) => {
impl $name {
fn f(&self) {}
}
}
}
do_impl!(X);
unless you use it:
fn main() {
X.f()
}
error[E0034]: multiple applicable items in scope
--> a.rs:14:7
|
14 | X.f()
| ^ multiple `f` found
|
note: candidate #1 is defined in an impl for the type `X`
--> a.rs:3:4
|
3 | fn f(&self) {}
| ^^^^^^^^^^^
note: candidate #2 is defined in an impl for the type `X`
--> a.rs:8:13
|
8 | fn f(&self) {}
| ^^^^^^^^^^^
...
12 | do_impl!(X);
| ------------ in this macro invocation
I think it should fail even when we don't use the duplicate function.