diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-06-22 15:02:44 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-06-22 15:02:44 +0000 |
| commit | 326a9fa8e890902abf1f4e8aaa5be9010b366f4c (patch) | |
| tree | 87755fb45aa32bd34b4e186b0cd817c0e403ae9f | |
| parent | 12243ec41586bd5b68c032ef456a369fb0350469 (diff) | |
| download | rust-326a9fa8e890902abf1f4e8aaa5be9010b366f4c.tar.gz rust-326a9fa8e890902abf1f4e8aaa5be9010b366f4c.zip | |
Add tests showcasing our short circuiting behaviour in the signature checks for defining scopes
| -rw-r--r-- | tests/ui/type-alias-impl-trait/multi-error.rs | 25 | ||||
| -rw-r--r-- | tests/ui/type-alias-impl-trait/multi-error.stderr | 49 | ||||
| -rw-r--r-- | tests/ui/type-alias-impl-trait/non-defining-method.rs | 22 | ||||
| -rw-r--r-- | tests/ui/type-alias-impl-trait/non-defining-method.stderr | 33 |
4 files changed, 129 insertions, 0 deletions
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<T>; + type Baz; + fn foo() -> (Self::Bar<u32>, Self::Baz); +} + +impl Foo for () { + type Bar<T> = impl Sized; + type Baz = impl Sized; + fn foo() -> (Self::Bar<u32>, 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<u32>, Self::Baz) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument `u32` is not a generic parameter + | +note: for this opaque type + --> $DIR/multi-error.rs:15:19 + | +LL | type Bar<T> = impl Sized; + | ^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/multi-error.rs:19:10 + | +LL | type Bar<T> = impl Sized; + | ---------- the expected opaque type +... +LL | ((), ()) + | ^^ expected opaque type, found `()` + | + = note: expected opaque type `<() as Foo>::Bar<u32>` + 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<u32>, 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<u32>, 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<T>; + fn foo() -> Self::Bar<u32>; + fn bar<T>() -> Self::Bar<T>; +} + +impl Foo for () { + type Bar<T> = impl Sized; + fn foo() -> Self::Bar<u32> {} + //~^ ERROR non-defining opaque type use + //~| ERROR mismatched types + fn bar<T>() -> Self::Bar<T> {} +} + +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<u32> {} + | ^^^^^^^^^^^^^^ argument `u32` is not a generic parameter + | +note: for this opaque type + --> $DIR/non-defining-method.rs:15:19 + | +LL | type Bar<T> = impl Sized; + | ^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/non-defining-method.rs:16:17 + | +LL | type Bar<T> = impl Sized; + | ---------- the expected opaque type +LL | fn foo() -> Self::Bar<u32> {} + | --- ^^^^^^^^^^^^^^ expected opaque type, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression + | + = note: expected opaque type `<() as Foo>::Bar<u32>` + 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<u32> {} + | ^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. |
