about summary refs log tree commit diff
path: root/tests/ui/methods
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-09-18 20:45:20 -0400
committerMichael Goulet <michael@errs.io>2025-02-13 05:45:53 +0000
commitf8c51d300285a63e458c2ba7c21f0d66e4f1f239 (patch)
tree944ce9faa4c6c9c991ddceb53de5bfe9e27a3d2a /tests/ui/methods
parent0c85044a5d5ab1aef40153a3de48eb67804f6677 (diff)
downloadrust-f8c51d300285a63e458c2ba7c21f0d66e4f1f239.tar.gz
rust-f8c51d300285a63e458c2ba7c21f0d66e4f1f239.zip
Implement shadowing lint
Diffstat (limited to 'tests/ui/methods')
-rw-r--r--tests/ui/methods/supertrait-shadowing/common-ancestor.rs25
-rw-r--r--tests/ui/methods/supertrait-shadowing/common-ancestor.run.stdout1
-rw-r--r--tests/ui/methods/supertrait-shadowing/common-ancestor.stderr24
-rw-r--r--tests/ui/methods/supertrait-shadowing/no-common-ancestor.rs20
-rw-r--r--tests/ui/methods/supertrait-shadowing/no-common-ancestor.stderr30
5 files changed, 100 insertions, 0 deletions
diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor.rs b/tests/ui/methods/supertrait-shadowing/common-ancestor.rs
new file mode 100644
index 00000000000..28f415a4772
--- /dev/null
+++ b/tests/ui/methods/supertrait-shadowing/common-ancestor.rs
@@ -0,0 +1,25 @@
+//@ run-pass
+//@ check-run-results
+
+#![feature(supertrait_item_shadowing)]
+#![warn(supertrait_item_shadowing_usage)]
+#![allow(dead_code)]
+
+trait A {
+    fn hello(&self) {
+        println!("A");
+    }
+}
+impl<T> A for T {}
+
+trait B: A {
+    fn hello(&self) {
+        println!("B");
+    }
+}
+impl<T> B for T {}
+
+fn main() {
+    ().hello();
+    //~^ WARN trait item `hello` from `B` shadows identically named item from supertrait
+}
diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor.run.stdout b/tests/ui/methods/supertrait-shadowing/common-ancestor.run.stdout
new file mode 100644
index 00000000000..223b7836fb1
--- /dev/null
+++ b/tests/ui/methods/supertrait-shadowing/common-ancestor.run.stdout
@@ -0,0 +1 @@
+B
diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor.stderr b/tests/ui/methods/supertrait-shadowing/common-ancestor.stderr
new file mode 100644
index 00000000000..8ba0529ad9f
--- /dev/null
+++ b/tests/ui/methods/supertrait-shadowing/common-ancestor.stderr
@@ -0,0 +1,24 @@
+warning: trait item `hello` from `B` shadows identically named item from supertrait
+  --> $DIR/common-ancestor.rs:23:8
+   |
+LL |     ().hello();
+   |        ^^^^^
+   |
+note: item from `B` shadows a supertrait item
+  --> $DIR/common-ancestor.rs:16:5
+   |
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+note: item from `A` is shadowed by a subtrait item
+  --> $DIR/common-ancestor.rs:9:5
+   |
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+note: the lint level is defined here
+  --> $DIR/common-ancestor.rs:5:9
+   |
+LL | #![warn(supertrait_item_shadowing_usage)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+warning: 1 warning emitted
+
diff --git a/tests/ui/methods/supertrait-shadowing/no-common-ancestor.rs b/tests/ui/methods/supertrait-shadowing/no-common-ancestor.rs
new file mode 100644
index 00000000000..7323439d588
--- /dev/null
+++ b/tests/ui/methods/supertrait-shadowing/no-common-ancestor.rs
@@ -0,0 +1,20 @@
+#![feature(supertrait_item_shadowing)]
+
+trait A {
+    fn hello(&self) {
+        println!("A");
+    }
+}
+impl<T> A for T {}
+
+trait B {
+    fn hello(&self) {
+        println!("B");
+    }
+}
+impl<T> B for T {}
+
+fn main() {
+    ().hello();
+    //~^ ERROR multiple applicable items in scope
+}
diff --git a/tests/ui/methods/supertrait-shadowing/no-common-ancestor.stderr b/tests/ui/methods/supertrait-shadowing/no-common-ancestor.stderr
new file mode 100644
index 00000000000..4e83f60c765
--- /dev/null
+++ b/tests/ui/methods/supertrait-shadowing/no-common-ancestor.stderr
@@ -0,0 +1,30 @@
+error[E0034]: multiple applicable items in scope
+  --> $DIR/no-common-ancestor.rs:18:8
+   |
+LL |     ().hello();
+   |        ^^^^^ multiple `hello` found
+   |
+note: candidate #1 is defined in an impl of the trait `A` for the type `T`
+  --> $DIR/no-common-ancestor.rs:4:5
+   |
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+note: candidate #2 is defined in an impl of the trait `B` for the type `T`
+  --> $DIR/no-common-ancestor.rs:11:5
+   |
+LL |     fn hello(&self) {
+   |     ^^^^^^^^^^^^^^^
+help: disambiguate the method for candidate #1
+   |
+LL -     ().hello();
+LL +     A::hello(&());
+   |
+help: disambiguate the method for candidate #2
+   |
+LL -     ().hello();
+LL +     B::hello(&());
+   |
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0034`.