about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2022-08-10 21:31:26 +0200
committerCamille GILLOT <gillot.camille@gmail.com>2022-10-11 06:24:51 +0000
commit152cd6322655bb5173655cdf0781ca64c2a7602f (patch)
treebd3c5ca31c99c70fddcba8b7e57e31d68da14eac /src/test
parent8796e7a9cfd4c5c4f1de15ec1c53994ddf288665 (diff)
Report duplicate definitions in trait impls during resolution.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/associated-item/associated-item-duplicate-names-3.rs1
-rw-r--r--src/test/ui/associated-item/associated-item-duplicate-names-3.stderr18
-rw-r--r--src/test/ui/associated-item/associated-item-duplicate-names.stderr14
-rw-r--r--src/test/ui/error-codes/E0201.stderr30
-rw-r--r--src/test/ui/hygiene/impl_items-2.rs26
-rw-r--r--src/test/ui/hygiene/impl_items-2.stderr15
-rw-r--r--src/test/ui/traits/issue-8153.stderr7
7 files changed, 89 insertions, 22 deletions
diff --git a/src/test/ui/associated-item/associated-item-duplicate-names-3.rs b/src/test/ui/associated-item/associated-item-duplicate-names-3.rs
index 6aa1b483eeb..3a70a2f943f 100644
--- a/src/test/ui/associated-item/associated-item-duplicate-names-3.rs
+++ b/src/test/ui/associated-item/associated-item-duplicate-names-3.rs
@@ -16,4 +16,5 @@ impl Foo for Baz {
 
 fn main() {
     let x: Baz::Bar = 5;
+    //~^ ERROR ambiguous associated type
 }
diff --git a/src/test/ui/associated-item/associated-item-duplicate-names-3.stderr b/src/test/ui/associated-item/associated-item-duplicate-names-3.stderr
index 03782f66348..bf4bd634cf1 100644
--- a/src/test/ui/associated-item/associated-item-duplicate-names-3.stderr
+++ b/src/test/ui/associated-item/associated-item-duplicate-names-3.stderr
@@ -1,11 +1,21 @@
 error[E0201]: duplicate definitions with name `Bar`:
   --> $DIR/associated-item-duplicate-names-3.rs:14:5
    |
+LL |     type Bar;
+   |     --------- item in trait
+...
 LL |     type Bar = i16;
-   |     -------- previous definition of `Bar` here
+   |     --------------- previous definition here
 LL |     type Bar = u16;
-   |     ^^^^^^^^ duplicate definition
+   |     ^^^^^^^^^^^^^^^ duplicate definition
 
-error: aborting due to previous error
+error[E0223]: ambiguous associated type
+  --> $DIR/associated-item-duplicate-names-3.rs:18:12
+   |
+LL |     let x: Baz::Bar = 5;
+   |            ^^^^^^^^ help: use fully-qualified syntax: `<Baz as Trait>::Bar`
+
+error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0201`.
+Some errors have detailed explanations: E0201, E0223.
+For more information about an error, try `rustc --explain E0201`.
diff --git a/src/test/ui/associated-item/associated-item-duplicate-names.stderr b/src/test/ui/associated-item/associated-item-duplicate-names.stderr
index c9119c10271..f89ea6e57cc 100644
--- a/src/test/ui/associated-item/associated-item-duplicate-names.stderr
+++ b/src/test/ui/associated-item/associated-item-duplicate-names.stderr
@@ -1,18 +1,24 @@
 error[E0201]: duplicate definitions with name `Ty`:
   --> $DIR/associated-item-duplicate-names.rs:11:5
    |
+LL |     type Ty;
+   |     -------- item in trait
+...
 LL |     type Ty = ();
-   |     ------- previous definition of `Ty` here
+   |     ------------- previous definition here
 LL |     type Ty = usize;
-   |     ^^^^^^^ duplicate definition
+   |     ^^^^^^^^^^^^^^^^ duplicate definition
 
 error[E0201]: duplicate definitions with name `BAR`:
   --> $DIR/associated-item-duplicate-names.rs:13:5
    |
+LL |     const BAR: u32;
+   |     --------------- item in trait
+...
 LL |     const BAR: u32 = 7;
-   |     -------------- previous definition of `BAR` here
+   |     ------------------- previous definition here
 LL |     const BAR: u32 = 8;
-   |     ^^^^^^^^^^^^^^ duplicate definition
+   |     ^^^^^^^^^^^^^^^^^^^ duplicate definition
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/error-codes/E0201.stderr b/src/test/ui/error-codes/E0201.stderr
index 94e06894144..f72145a8244 100644
--- a/src/test/ui/error-codes/E0201.stderr
+++ b/src/test/ui/error-codes/E0201.stderr
@@ -1,27 +1,33 @@
-error[E0201]: duplicate definitions with name `bar`:
-  --> $DIR/E0201.rs:5:5
-   |
-LL |     fn bar(&self) -> bool { self.0 > 5 }
-   |     --------------------- previous definition of `bar` here
-LL |     fn bar() {}
-   |     ^^^^^^^^ duplicate definition
-
 error[E0201]: duplicate definitions with name `baz`:
   --> $DIR/E0201.rs:17:5
    |
+LL |     fn baz(&self) -> bool;
+   |     ---------------------- item in trait
+...
 LL |     fn baz(&self) -> bool { true }
-   |     --------------------- previous definition of `baz` here
+   |     ------------------------------ previous definition here
 LL |     fn baz(&self) -> bool { self.0 > 5 }
-   |     ^^^^^^^^^^^^^^^^^^^^^ duplicate definition
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definition
 
 error[E0201]: duplicate definitions with name `Quux`:
   --> $DIR/E0201.rs:18:5
    |
+LL |     type Quux;
+   |     ---------- item in trait
+...
 LL |     type Quux = u32;
-   |     --------- previous definition of `Quux` here
+   |     ---------------- previous definition here
 ...
 LL |     type Quux = u32;
-   |     ^^^^^^^^^ duplicate definition
+   |     ^^^^^^^^^^^^^^^^ duplicate definition
+
+error[E0201]: duplicate definitions with name `bar`:
+  --> $DIR/E0201.rs:5:5
+   |
+LL |     fn bar(&self) -> bool { self.0 > 5 }
+   |     --------------------- previous definition of `bar` here
+LL |     fn bar() {}
+   |     ^^^^^^^^ duplicate definition
 
 error: aborting due to 3 previous errors
 
diff --git a/src/test/ui/hygiene/impl_items-2.rs b/src/test/ui/hygiene/impl_items-2.rs
new file mode 100644
index 00000000000..465e444aedb
--- /dev/null
+++ b/src/test/ui/hygiene/impl_items-2.rs
@@ -0,0 +1,26 @@
+#![feature(decl_macro)]
+
+trait Trait {
+    fn foo() {}
+}
+
+macro trait_impl() {
+    fn foo() {}
+}
+
+// Check that we error on multiple impl items that resolve to the same trait item.
+impl Trait for i32 {
+    trait_impl!();
+    fn foo() {}
+    //~^ ERROR duplicate definitions with name `foo`: [E0201]
+}
+
+struct Type;
+
+// Check that we do not error with inherent impls.
+impl Type {
+    trait_impl!();
+    fn foo() {}
+}
+
+fn main() {}
diff --git a/src/test/ui/hygiene/impl_items-2.stderr b/src/test/ui/hygiene/impl_items-2.stderr
new file mode 100644
index 00000000000..3c0ffeb1057
--- /dev/null
+++ b/src/test/ui/hygiene/impl_items-2.stderr
@@ -0,0 +1,15 @@
+error[E0201]: duplicate definitions with name `foo`:
+  --> $DIR/impl_items-2.rs:14:5
+   |
+LL |     fn foo() {}
+   |     ----------- item in trait
+...
+LL |     fn foo() {}
+   |     ----------- previous definition here
+...
+LL |     fn foo() {}
+   |     ^^^^^^^^^^^ duplicate definition
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0201`.
diff --git a/src/test/ui/traits/issue-8153.stderr b/src/test/ui/traits/issue-8153.stderr
index b76bbc0235f..ae214bb9e9b 100644
--- a/src/test/ui/traits/issue-8153.stderr
+++ b/src/test/ui/traits/issue-8153.stderr
@@ -1,10 +1,13 @@
 error[E0201]: duplicate definitions with name `bar`:
   --> $DIR/issue-8153.rs:11:5
    |
+LL |     fn bar(&self) -> isize;
+   |     ----------------------- item in trait
+...
 LL |     fn bar(&self) -> isize {1}
-   |     ---------------------- previous definition of `bar` here
+   |     -------------------------- previous definition here
 LL |     fn bar(&self) -> isize {2}
-   |     ^^^^^^^^^^^^^^^^^^^^^^ duplicate definition
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definition
 
 error: aborting due to previous error