Add tests showcasing our short circuiting behaviour in the signature checks for defining scopes

This commit is contained in:
Oli Scherer 2023-06-22 15:02:44 +00:00
parent 12243ec415
commit 326a9fa8e8
4 changed files with 129 additions and 0 deletions

View File

@ -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() {}

View File

@ -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`.

View File

@ -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() {}

View File

@ -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`.