diff options
| author | Michael Goulet <michael@errs.io> | 2024-09-18 21:15:46 -0400 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-02-13 05:45:53 +0000 |
| commit | 18a3cc5c2c8b6cf3ff2e3313e5add69c7c6ff7ea (patch) | |
| tree | 4a2bf9729ba5f41994e87799ef567b64d474474b /tests/ui/methods | |
| parent | f8c51d300285a63e458c2ba7c21f0d66e4f1f239 (diff) | |
Rework collapse method to work correctly with more complex supertrait graphs
Diffstat (limited to 'tests/ui/methods')
8 files changed, 219 insertions, 0 deletions
diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor-2.rs b/tests/ui/methods/supertrait-shadowing/common-ancestor-2.rs new file mode 100644 index 00000000000..91a64561824 --- /dev/null +++ b/tests/ui/methods/supertrait-shadowing/common-ancestor-2.rs @@ -0,0 +1,32 @@ +//@ 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 { + fn hello(&self) { + println!("B"); + } +} +impl<T> B for T {} + +trait C: A + B { + fn hello(&self) { + println!("C"); + } +} +impl<T> C for T {} + +fn main() { + ().hello(); + //~^ WARN trait item `hello` from `C` shadows identically named item from supertrait +} diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor-2.run.stdout b/tests/ui/methods/supertrait-shadowing/common-ancestor-2.run.stdout new file mode 100644 index 00000000000..3cc58df8375 --- /dev/null +++ b/tests/ui/methods/supertrait-shadowing/common-ancestor-2.run.stdout @@ -0,0 +1 @@ +C diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor-2.stderr b/tests/ui/methods/supertrait-shadowing/common-ancestor-2.stderr new file mode 100644 index 00000000000..a22c5430fef --- /dev/null +++ b/tests/ui/methods/supertrait-shadowing/common-ancestor-2.stderr @@ -0,0 +1,27 @@ +warning: trait item `hello` from `C` shadows identically named item from supertrait + --> $DIR/common-ancestor-2.rs:30:8 + | +LL | ().hello(); + | ^^^^^ + | +note: item from `C` shadows a supertrait item + --> $DIR/common-ancestor-2.rs:23:5 + | +LL | fn hello(&self) { + | ^^^^^^^^^^^^^^^ +note: items from several supertraits are shadowed: `A` and `B` + --> $DIR/common-ancestor-2.rs:9:5 + | +LL | fn hello(&self) { + | ^^^^^^^^^^^^^^^ +... +LL | fn hello(&self) { + | ^^^^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/common-ancestor-2.rs:5:9 + | +LL | #![warn(supertrait_item_shadowing_usage)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: 1 warning emitted + diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor-3.rs b/tests/ui/methods/supertrait-shadowing/common-ancestor-3.rs new file mode 100644 index 00000000000..c2b0ef39bb1 --- /dev/null +++ b/tests/ui/methods/supertrait-shadowing/common-ancestor-3.rs @@ -0,0 +1,41 @@ +//@ 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 { + fn hello(&self) { + println!("B"); + } +} +impl<T> B for T {} + +trait C: A + B { + fn hello(&self) { + println!("C"); + } +} +impl<T> C for T {} + +// `D` extends `C` which extends `B` and `A` + +trait D: C { + fn hello(&self) { + println!("D"); + } +} +impl<T> D for T {} + +fn main() { + ().hello(); + //~^ WARN trait item `hello` from `D` shadows identically named item from supertrait +} diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor-3.run.stdout b/tests/ui/methods/supertrait-shadowing/common-ancestor-3.run.stdout new file mode 100644 index 00000000000..17848105018 --- /dev/null +++ b/tests/ui/methods/supertrait-shadowing/common-ancestor-3.run.stdout @@ -0,0 +1 @@ +D diff --git a/tests/ui/methods/supertrait-shadowing/common-ancestor-3.stderr b/tests/ui/methods/supertrait-shadowing/common-ancestor-3.stderr new file mode 100644 index 00000000000..072f4fe0208 --- /dev/null +++ b/tests/ui/methods/supertrait-shadowing/common-ancestor-3.stderr @@ -0,0 +1,30 @@ +warning: trait item `hello` from `D` shadows identically named item from supertrait + --> $DIR/common-ancestor-3.rs:39:8 + | +LL | ().hello(); + | ^^^^^ + | +note: item from `D` shadows a supertrait item + --> $DIR/common-ancestor-3.rs:32:5 + | +LL | fn hello(&self) { + | ^^^^^^^^^^^^^^^ +note: items from several supertraits are shadowed: `A`, `B`, and `C` + --> $DIR/common-ancestor-3.rs:9:5 + | +LL | fn hello(&self) { + | ^^^^^^^^^^^^^^^ +... +LL | fn hello(&self) { + | ^^^^^^^^^^^^^^^ +... +LL | fn hello(&self) { + | ^^^^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/common-ancestor-3.rs:5:9 + | +LL | #![warn(supertrait_item_shadowing_usage)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: 1 warning emitted + diff --git a/tests/ui/methods/supertrait-shadowing/no-common-ancestor-2.rs b/tests/ui/methods/supertrait-shadowing/no-common-ancestor-2.rs new file mode 100644 index 00000000000..2834ca31b71 --- /dev/null +++ b/tests/ui/methods/supertrait-shadowing/no-common-ancestor-2.rs @@ -0,0 +1,37 @@ +#![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 {} + +trait C: A + B { + fn hello(&self) { + println!("C"); + } +} +impl<T> C for T {} + +// Since `D` is not a subtrait of `C`, +// we have no obvious lower bound. + +trait D: B { + fn hello(&self) { + println!("D"); + } +} +impl<T> D for T {} + +fn main() { + ().hello(); + //~^ ERROR multiple applicable items in scope +} diff --git a/tests/ui/methods/supertrait-shadowing/no-common-ancestor-2.stderr b/tests/ui/methods/supertrait-shadowing/no-common-ancestor-2.stderr new file mode 100644 index 00000000000..231cb9b1cb2 --- /dev/null +++ b/tests/ui/methods/supertrait-shadowing/no-common-ancestor-2.stderr @@ -0,0 +1,50 @@ +error[E0034]: multiple applicable items in scope + --> $DIR/no-common-ancestor-2.rs:35: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-2.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-2.rs:11:5 + | +LL | fn hello(&self) { + | ^^^^^^^^^^^^^^^ +note: candidate #3 is defined in an impl of the trait `C` for the type `T` + --> $DIR/no-common-ancestor-2.rs:18:5 + | +LL | fn hello(&self) { + | ^^^^^^^^^^^^^^^ +note: candidate #4 is defined in an impl of the trait `D` for the type `T` + --> $DIR/no-common-ancestor-2.rs:28: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(&()); + | +help: disambiguate the method for candidate #3 + | +LL - ().hello(); +LL + C::hello(&()); + | +help: disambiguate the method for candidate #4 + | +LL - ().hello(); +LL + D::hello(&()); + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0034`. |
