- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
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.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.