From 326a9fa8e890902abf1f4e8aaa5be9010b366f4c Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 22 Jun 2023 15:02:44 +0000 Subject: [PATCH] Add tests showcasing our short circuiting behaviour in the signature checks for defining scopes --- tests/ui/type-alias-impl-trait/multi-error.rs | 25 ++++++++++ .../type-alias-impl-trait/multi-error.stderr | 49 +++++++++++++++++++ .../non-defining-method.rs | 22 +++++++++ .../non-defining-method.stderr | 33 +++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 tests/ui/type-alias-impl-trait/multi-error.rs create mode 100644 tests/ui/type-alias-impl-trait/multi-error.stderr create mode 100644 tests/ui/type-alias-impl-trait/non-defining-method.rs create mode 100644 tests/ui/type-alias-impl-trait/non-defining-method.stderr diff --git a/tests/ui/type-alias-impl-trait/multi-error.rs b/tests/ui/type-alias-impl-trait/multi-error.rs new file mode 100644 index 00000000000..d10967abf9a --- /dev/null +++ b/tests/ui/type-alias-impl-trait/multi-error.rs @@ -0,0 +1,25 @@ +//! This test checks that we don't follow up +//! with type mismatch errors of opaque types +//! with their hidden types if we failed the +//! defining scope check at the signature level. + +#![feature(impl_trait_in_assoc_type)] + +trait Foo { + type Bar; + type Baz; + fn foo() -> (Self::Bar, Self::Baz); +} + +impl Foo for () { + type Bar = impl Sized; + type Baz = impl Sized; + fn foo() -> (Self::Bar, Self::Baz) { + //~^ ERROR non-defining opaque type use + ((), ()) + //~^ ERROR mismatched types + //~| ERROR mismatched types + } +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/multi-error.stderr b/tests/ui/type-alias-impl-trait/multi-error.stderr new file mode 100644 index 00000000000..17259373749 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/multi-error.stderr @@ -0,0 +1,49 @@ +error: non-defining opaque type use in defining scope + --> $DIR/multi-error.rs:17:17 + | +LL | fn foo() -> (Self::Bar, Self::Baz) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument `u32` is not a generic parameter + | +note: for this opaque type + --> $DIR/multi-error.rs:15:19 + | +LL | type Bar = impl Sized; + | ^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/multi-error.rs:19:10 + | +LL | type Bar = impl Sized; + | ---------- the expected opaque type +... +LL | ((), ()) + | ^^ expected opaque type, found `()` + | + = note: expected opaque type `<() as Foo>::Bar` + found unit type `()` +note: this item must have the opaque type in its signature in order to be able to register hidden types + --> $DIR/multi-error.rs:17:8 + | +LL | fn foo() -> (Self::Bar, Self::Baz) { + | ^^^ + +error[E0308]: mismatched types + --> $DIR/multi-error.rs:19:14 + | +LL | type Baz = impl Sized; + | ---------- the expected opaque type +... +LL | ((), ()) + | ^^ expected opaque type, found `()` + | + = note: expected opaque type `<() as Foo>::Baz` + found unit type `()` +note: this item must have the opaque type in its signature in order to be able to register hidden types + --> $DIR/multi-error.rs:17:8 + | +LL | fn foo() -> (Self::Bar, Self::Baz) { + | ^^^ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/non-defining-method.rs b/tests/ui/type-alias-impl-trait/non-defining-method.rs new file mode 100644 index 00000000000..66ceedee8f7 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/non-defining-method.rs @@ -0,0 +1,22 @@ +//! This test checks that we don't follow up +//! with type mismatch errors of opaque types +//! with their hidden types if we failed the +//! defining scope check at the signature level. + +#![feature(impl_trait_in_assoc_type)] + +trait Foo { + type Bar; + fn foo() -> Self::Bar; + fn bar() -> Self::Bar; +} + +impl Foo for () { + type Bar = impl Sized; + fn foo() -> Self::Bar {} + //~^ ERROR non-defining opaque type use + //~| ERROR mismatched types + fn bar() -> Self::Bar {} +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/non-defining-method.stderr b/tests/ui/type-alias-impl-trait/non-defining-method.stderr new file mode 100644 index 00000000000..f203cff9036 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/non-defining-method.stderr @@ -0,0 +1,33 @@ +error: non-defining opaque type use in defining scope + --> $DIR/non-defining-method.rs:16:17 + | +LL | fn foo() -> Self::Bar {} + | ^^^^^^^^^^^^^^ argument `u32` is not a generic parameter + | +note: for this opaque type + --> $DIR/non-defining-method.rs:15:19 + | +LL | type Bar = impl Sized; + | ^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/non-defining-method.rs:16:17 + | +LL | type Bar = impl Sized; + | ---------- the expected opaque type +LL | fn foo() -> Self::Bar {} + | --- ^^^^^^^^^^^^^^ expected opaque type, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression + | + = note: expected opaque type `<() as Foo>::Bar` + found unit type `()` +note: this item must have the opaque type in its signature in order to be able to register hidden types + --> $DIR/non-defining-method.rs:16:8 + | +LL | fn foo() -> Self::Bar {} + | ^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`.