about summary refs log tree commit diff
path: root/tests/ui/methods
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-01-25 17:14:33 +0000
committerMichael Goulet <michael@errs.io>2025-02-13 05:45:53 +0000
commit72b4df3772a6c2cae8d9cf7ae618c010c10131b2 (patch)
tree7c2d611b8fce4d6776b7579df0a65d8078399290 /tests/ui/methods
parent2189908170f86809b7de5275dcde0cf828c16b37 (diff)
downloadrust-72b4df3772a6c2cae8d9cf7ae618c010c10131b2.tar.gz
rust-72b4df3772a6c2cae8d9cf7ae618c010c10131b2.zip
Implement lint for definition site item shadowing too
Diffstat (limited to 'tests/ui/methods')
-rw-r--r--tests/ui/methods/supertrait-shadowing/common-ancestor-2.rs2
-rw-r--r--tests/ui/methods/supertrait-shadowing/common-ancestor-2.stderr28
-rw-r--r--tests/ui/methods/supertrait-shadowing/common-ancestor-3.rs3
-rw-r--r--tests/ui/methods/supertrait-shadowing/common-ancestor-3.stderr46
-rw-r--r--tests/ui/methods/supertrait-shadowing/common-ancestor.rs2
-rw-r--r--tests/ui/methods/supertrait-shadowing/common-ancestor.stderr25
-rw-r--r--tests/ui/methods/supertrait-shadowing/definition-site.rs18
-rw-r--r--tests/ui/methods/supertrait-shadowing/definition-site.stderr34
-rw-r--r--tests/ui/methods/supertrait-shadowing/false-subtrait-after-inference.rs2
-rw-r--r--tests/ui/methods/supertrait-shadowing/false-subtrait-after-inference.stderr31
10 files changed, 172 insertions, 19 deletions
diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor-2.rs b/tests/ui/methods/supertrait-shadowing/common-ancestor-2.rs
index 91a64561824..cecf6dccf9d 100644
--- a/tests/ui/methods/supertrait-shadowing/common-ancestor-2.rs
+++ b/tests/ui/methods/supertrait-shadowing/common-ancestor-2.rs
@@ -3,6 +3,7 @@
 
 #![feature(supertrait_item_shadowing)]
 #![warn(supertrait_item_shadowing_usage)]
+#![warn(supertrait_item_shadowing_definition)]
 #![allow(dead_code)]
 
 trait A {
@@ -21,6 +22,7 @@ impl<T> B for T {}
 
 trait C: A + B {
     fn hello(&self) {
+        //~^ WARN trait item `hello` from `C` shadows identically named item
         println!("C");
     }
 }
diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor-2.stderr b/tests/ui/methods/supertrait-shadowing/common-ancestor-2.stderr
index a22c5430fef..934d5a0f7cf 100644
--- a/tests/ui/methods/supertrait-shadowing/common-ancestor-2.stderr
+++ b/tests/ui/methods/supertrait-shadowing/common-ancestor-2.stderr
@@ -1,16 +1,36 @@
 warning: trait item `hello` from `C` shadows identically named item from supertrait
-  --> $DIR/common-ancestor-2.rs:30:8
+  --> $DIR/common-ancestor-2.rs:24:5
+   |
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+   |
+note: items from several supertraits are shadowed: `B` and `A`
+  --> $DIR/common-ancestor-2.rs:10:5
+   |
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+...
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+note: the lint level is defined here
+  --> $DIR/common-ancestor-2.rs:6:9
+   |
+LL | #![warn(supertrait_item_shadowing_definition)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+warning: trait item `hello` from `C` shadows identically named item from supertrait
+  --> $DIR/common-ancestor-2.rs:32:8
    |
 LL |     ().hello();
    |        ^^^^^
    |
 note: item from `C` shadows a supertrait item
-  --> $DIR/common-ancestor-2.rs:23:5
+  --> $DIR/common-ancestor-2.rs:24:5
    |
 LL |     fn hello(&self) {
    |     ^^^^^^^^^^^^^^^
 note: items from several supertraits are shadowed: `A` and `B`
-  --> $DIR/common-ancestor-2.rs:9:5
+  --> $DIR/common-ancestor-2.rs:10:5
    |
 LL |     fn hello(&self) {
    |     ^^^^^^^^^^^^^^^
@@ -23,5 +43,5 @@ note: the lint level is defined here
 LL | #![warn(supertrait_item_shadowing_usage)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-warning: 1 warning emitted
+warning: 2 warnings emitted
 
diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor-3.rs b/tests/ui/methods/supertrait-shadowing/common-ancestor-3.rs
index c2b0ef39bb1..040fa9aab39 100644
--- a/tests/ui/methods/supertrait-shadowing/common-ancestor-3.rs
+++ b/tests/ui/methods/supertrait-shadowing/common-ancestor-3.rs
@@ -3,6 +3,7 @@
 
 #![feature(supertrait_item_shadowing)]
 #![warn(supertrait_item_shadowing_usage)]
+#![warn(supertrait_item_shadowing_definition)]
 #![allow(dead_code)]
 
 trait A {
@@ -21,6 +22,7 @@ impl<T> B for T {}
 
 trait C: A + B {
     fn hello(&self) {
+        //~^ WARN trait item `hello` from `C` shadows identically named item
         println!("C");
     }
 }
@@ -30,6 +32,7 @@ impl<T> C for T {}
 
 trait D: C {
     fn hello(&self) {
+        //~^ WARN trait item `hello` from `D` shadows identically named item
         println!("D");
     }
 }
diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor-3.stderr b/tests/ui/methods/supertrait-shadowing/common-ancestor-3.stderr
index 072f4fe0208..28e44a2ff20 100644
--- a/tests/ui/methods/supertrait-shadowing/common-ancestor-3.stderr
+++ b/tests/ui/methods/supertrait-shadowing/common-ancestor-3.stderr
@@ -1,16 +1,54 @@
+warning: trait item `hello` from `C` shadows identically named item from supertrait
+  --> $DIR/common-ancestor-3.rs:24:5
+   |
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+   |
+note: items from several supertraits are shadowed: `B` and `A`
+  --> $DIR/common-ancestor-3.rs:10:5
+   |
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+...
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+note: the lint level is defined here
+  --> $DIR/common-ancestor-3.rs:6:9
+   |
+LL | #![warn(supertrait_item_shadowing_definition)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+warning: trait item `hello` from `D` shadows identically named item from supertrait
+  --> $DIR/common-ancestor-3.rs:34:5
+   |
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+   |
+note: items from several supertraits are shadowed: `C`, `B`, and `A`
+  --> $DIR/common-ancestor-3.rs:10:5
+   |
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+...
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+...
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+
 warning: trait item `hello` from `D` shadows identically named item from supertrait
-  --> $DIR/common-ancestor-3.rs:39:8
+  --> $DIR/common-ancestor-3.rs:42:8
    |
 LL |     ().hello();
    |        ^^^^^
    |
 note: item from `D` shadows a supertrait item
-  --> $DIR/common-ancestor-3.rs:32:5
+  --> $DIR/common-ancestor-3.rs:34:5
    |
 LL |     fn hello(&self) {
    |     ^^^^^^^^^^^^^^^
 note: items from several supertraits are shadowed: `A`, `B`, and `C`
-  --> $DIR/common-ancestor-3.rs:9:5
+  --> $DIR/common-ancestor-3.rs:10:5
    |
 LL |     fn hello(&self) {
    |     ^^^^^^^^^^^^^^^
@@ -26,5 +64,5 @@ note: the lint level is defined here
 LL | #![warn(supertrait_item_shadowing_usage)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-warning: 1 warning emitted
+warning: 3 warnings emitted
 
diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor.rs b/tests/ui/methods/supertrait-shadowing/common-ancestor.rs
index 28f415a4772..8e67c935367 100644
--- a/tests/ui/methods/supertrait-shadowing/common-ancestor.rs
+++ b/tests/ui/methods/supertrait-shadowing/common-ancestor.rs
@@ -3,6 +3,7 @@
 
 #![feature(supertrait_item_shadowing)]
 #![warn(supertrait_item_shadowing_usage)]
+#![warn(supertrait_item_shadowing_definition)]
 #![allow(dead_code)]
 
 trait A {
@@ -14,6 +15,7 @@ impl<T> A for T {}
 
 trait B: A {
     fn hello(&self) {
+        //~^ WARN trait item `hello` from `B` shadows identically named item
         println!("B");
     }
 }
diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor.stderr b/tests/ui/methods/supertrait-shadowing/common-ancestor.stderr
index 8ba0529ad9f..f404fa6b53a 100644
--- a/tests/ui/methods/supertrait-shadowing/common-ancestor.stderr
+++ b/tests/ui/methods/supertrait-shadowing/common-ancestor.stderr
@@ -1,16 +1,33 @@
 warning: trait item `hello` from `B` shadows identically named item from supertrait
-  --> $DIR/common-ancestor.rs:23:8
+  --> $DIR/common-ancestor.rs:17:5
+   |
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+   |
+note: item from `A` is shadowed by a subtrait item
+  --> $DIR/common-ancestor.rs:10:5
+   |
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+note: the lint level is defined here
+  --> $DIR/common-ancestor.rs:6:9
+   |
+LL | #![warn(supertrait_item_shadowing_definition)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+warning: trait item `hello` from `B` shadows identically named item from supertrait
+  --> $DIR/common-ancestor.rs:25:8
    |
 LL |     ().hello();
    |        ^^^^^
    |
 note: item from `B` shadows a supertrait item
-  --> $DIR/common-ancestor.rs:16:5
+  --> $DIR/common-ancestor.rs:17:5
    |
 LL |     fn hello(&self) {
    |     ^^^^^^^^^^^^^^^
 note: item from `A` is shadowed by a subtrait item
-  --> $DIR/common-ancestor.rs:9:5
+  --> $DIR/common-ancestor.rs:10:5
    |
 LL |     fn hello(&self) {
    |     ^^^^^^^^^^^^^^^
@@ -20,5 +37,5 @@ note: the lint level is defined here
 LL | #![warn(supertrait_item_shadowing_usage)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-warning: 1 warning emitted
+warning: 2 warnings emitted
 
diff --git a/tests/ui/methods/supertrait-shadowing/definition-site.rs b/tests/ui/methods/supertrait-shadowing/definition-site.rs
new file mode 100644
index 00000000000..2768a6a6b27
--- /dev/null
+++ b/tests/ui/methods/supertrait-shadowing/definition-site.rs
@@ -0,0 +1,18 @@
+#![feature(supertrait_item_shadowing)]
+#![deny(supertrait_item_shadowing_definition)]
+
+trait SuperSuper {
+    fn method();
+}
+
+trait Super: SuperSuper {
+    fn method();
+    //~^ ERROR trait item `method` from `Super` shadows identically named item
+}
+
+trait Sub: Super {
+    fn method();
+    //~^ ERROR trait item `method` from `Sub` shadows identically named item
+}
+
+fn main() {}
diff --git a/tests/ui/methods/supertrait-shadowing/definition-site.stderr b/tests/ui/methods/supertrait-shadowing/definition-site.stderr
new file mode 100644
index 00000000000..f0bbf414a69
--- /dev/null
+++ b/tests/ui/methods/supertrait-shadowing/definition-site.stderr
@@ -0,0 +1,34 @@
+error: trait item `method` from `Super` shadows identically named item from supertrait
+  --> $DIR/definition-site.rs:9:5
+   |
+LL |     fn method();
+   |     ^^^^^^^^^^^^
+   |
+note: item from `SuperSuper` is shadowed by a subtrait item
+  --> $DIR/definition-site.rs:5:5
+   |
+LL |     fn method();
+   |     ^^^^^^^^^^^^
+note: the lint level is defined here
+  --> $DIR/definition-site.rs:2:9
+   |
+LL | #![deny(supertrait_item_shadowing_definition)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: trait item `method` from `Sub` shadows identically named item from supertrait
+  --> $DIR/definition-site.rs:14:5
+   |
+LL |     fn method();
+   |     ^^^^^^^^^^^^
+   |
+note: items from several supertraits are shadowed: `Super` and `SuperSuper`
+  --> $DIR/definition-site.rs:5:5
+   |
+LL |     fn method();
+   |     ^^^^^^^^^^^^
+...
+LL |     fn method();
+   |     ^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/methods/supertrait-shadowing/false-subtrait-after-inference.rs b/tests/ui/methods/supertrait-shadowing/false-subtrait-after-inference.rs
index 7cafb0c7ebd..c3bc47e6740 100644
--- a/tests/ui/methods/supertrait-shadowing/false-subtrait-after-inference.rs
+++ b/tests/ui/methods/supertrait-shadowing/false-subtrait-after-inference.rs
@@ -1,5 +1,6 @@
 #![feature(supertrait_item_shadowing)]
 #![warn(supertrait_item_shadowing_usage)]
+#![warn(supertrait_item_shadowing_definition)]
 
 struct W<T>(T);
 
@@ -10,6 +11,7 @@ impl<T> Upstream for T {}
 
 trait Downstream: Upstream {
     fn hello(&self) {}
+    //~^ WARN trait item `hello` from `Downstream` shadows identically named item
 }
 impl<T> Downstream for W<T> where T: Foo {}
 
diff --git a/tests/ui/methods/supertrait-shadowing/false-subtrait-after-inference.stderr b/tests/ui/methods/supertrait-shadowing/false-subtrait-after-inference.stderr
index c0555b95f3c..47019ca7a32 100644
--- a/tests/ui/methods/supertrait-shadowing/false-subtrait-after-inference.stderr
+++ b/tests/ui/methods/supertrait-shadowing/false-subtrait-after-inference.stderr
@@ -1,16 +1,33 @@
 warning: trait item `hello` from `Downstream` shadows identically named item from supertrait
-  --> $DIR/false-subtrait-after-inference.rs:20:7
+  --> $DIR/false-subtrait-after-inference.rs:13:5
+   |
+LL |     fn hello(&self) {}
+   |     ^^^^^^^^^^^^^^^
+   |
+note: item from `Upstream` is shadowed by a subtrait item
+  --> $DIR/false-subtrait-after-inference.rs:8:5
+   |
+LL |     fn hello(&self) {}
+   |     ^^^^^^^^^^^^^^^
+note: the lint level is defined here
+  --> $DIR/false-subtrait-after-inference.rs:3:9
+   |
+LL | #![warn(supertrait_item_shadowing_definition)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+warning: trait item `hello` from `Downstream` shadows identically named item from supertrait
+  --> $DIR/false-subtrait-after-inference.rs:22:7
    |
 LL |     x.hello();
    |       ^^^^^
    |
 note: item from `Downstream` shadows a supertrait item
-  --> $DIR/false-subtrait-after-inference.rs:12:5
+  --> $DIR/false-subtrait-after-inference.rs:13:5
    |
 LL |     fn hello(&self) {}
    |     ^^^^^^^^^^^^^^^
 note: item from `Upstream` is shadowed by a subtrait item
-  --> $DIR/false-subtrait-after-inference.rs:7:5
+  --> $DIR/false-subtrait-after-inference.rs:8:5
    |
 LL |     fn hello(&self) {}
    |     ^^^^^^^^^^^^^^^
@@ -21,22 +38,22 @@ LL | #![warn(supertrait_item_shadowing_usage)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0277]: the trait bound `i32: Foo` is not satisfied
-  --> $DIR/false-subtrait-after-inference.rs:20:7
+  --> $DIR/false-subtrait-after-inference.rs:22:7
    |
 LL |     x.hello();
    |       ^^^^^ the trait `Foo` is not implemented for `i32`
    |
 help: this trait has no implementations, consider adding one
-  --> $DIR/false-subtrait-after-inference.rs:16:1
+  --> $DIR/false-subtrait-after-inference.rs:18:1
    |
 LL | trait Foo {}
    | ^^^^^^^^^
 note: required for `W<i32>` to implement `Downstream`
-  --> $DIR/false-subtrait-after-inference.rs:14:9
+  --> $DIR/false-subtrait-after-inference.rs:16:9
    |
 LL | impl<T> Downstream for W<T> where T: Foo {}
    |         ^^^^^^^^^^     ^^^^          --- unsatisfied trait bound introduced here
 
-error: aborting due to 1 previous error; 1 warning emitted
+error: aborting due to 1 previous error; 2 warnings emitted
 
 For more information about this error, try `rustc --explain E0277`.