Skip to content

Commit 326a9fa

Browse files
committed
Add tests showcasing our short circuiting behaviour in the signature checks for defining scopes
1 parent 12243ec commit 326a9fa

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! This test checks that we don't follow up
2+
//! with type mismatch errors of opaque types
3+
//! with their hidden types if we failed the
4+
//! defining scope check at the signature level.
5+
6+
#![feature(impl_trait_in_assoc_type)]
7+
8+
trait Foo {
9+
type Bar<T>;
10+
type Baz;
11+
fn foo() -> (Self::Bar<u32>, Self::Baz);
12+
}
13+
14+
impl Foo for () {
15+
type Bar<T> = impl Sized;
16+
type Baz = impl Sized;
17+
fn foo() -> (Self::Bar<u32>, Self::Baz) {
18+
//~^ ERROR non-defining opaque type use
19+
((), ())
20+
//~^ ERROR mismatched types
21+
//~| ERROR mismatched types
22+
}
23+
}
24+
25+
fn main() {}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
error: non-defining opaque type use in defining scope
2+
--> $DIR/multi-error.rs:17:17
3+
|
4+
LL | fn foo() -> (Self::Bar<u32>, Self::Baz) {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument `u32` is not a generic parameter
6+
|
7+
note: for this opaque type
8+
--> $DIR/multi-error.rs:15:19
9+
|
10+
LL | type Bar<T> = impl Sized;
11+
| ^^^^^^^^^^
12+
13+
error[E0308]: mismatched types
14+
--> $DIR/multi-error.rs:19:10
15+
|
16+
LL | type Bar<T> = impl Sized;
17+
| ---------- the expected opaque type
18+
...
19+
LL | ((), ())
20+
| ^^ expected opaque type, found `()`
21+
|
22+
= note: expected opaque type `<() as Foo>::Bar<u32>`
23+
found unit type `()`
24+
note: this item must have the opaque type in its signature in order to be able to register hidden types
25+
--> $DIR/multi-error.rs:17:8
26+
|
27+
LL | fn foo() -> (Self::Bar<u32>, Self::Baz) {
28+
| ^^^
29+
30+
error[E0308]: mismatched types
31+
--> $DIR/multi-error.rs:19:14
32+
|
33+
LL | type Baz = impl Sized;
34+
| ---------- the expected opaque type
35+
...
36+
LL | ((), ())
37+
| ^^ expected opaque type, found `()`
38+
|
39+
= note: expected opaque type `<() as Foo>::Baz`
40+
found unit type `()`
41+
note: this item must have the opaque type in its signature in order to be able to register hidden types
42+
--> $DIR/multi-error.rs:17:8
43+
|
44+
LL | fn foo() -> (Self::Bar<u32>, Self::Baz) {
45+
| ^^^
46+
47+
error: aborting due to 3 previous errors
48+
49+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! This test checks that we don't follow up
2+
//! with type mismatch errors of opaque types
3+
//! with their hidden types if we failed the
4+
//! defining scope check at the signature level.
5+
6+
#![feature(impl_trait_in_assoc_type)]
7+
8+
trait Foo {
9+
type Bar<T>;
10+
fn foo() -> Self::Bar<u32>;
11+
fn bar<T>() -> Self::Bar<T>;
12+
}
13+
14+
impl Foo for () {
15+
type Bar<T> = impl Sized;
16+
fn foo() -> Self::Bar<u32> {}
17+
//~^ ERROR non-defining opaque type use
18+
//~| ERROR mismatched types
19+
fn bar<T>() -> Self::Bar<T> {}
20+
}
21+
22+
fn main() {}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error: non-defining opaque type use in defining scope
2+
--> $DIR/non-defining-method.rs:16:17
3+
|
4+
LL | fn foo() -> Self::Bar<u32> {}
5+
| ^^^^^^^^^^^^^^ argument `u32` is not a generic parameter
6+
|
7+
note: for this opaque type
8+
--> $DIR/non-defining-method.rs:15:19
9+
|
10+
LL | type Bar<T> = impl Sized;
11+
| ^^^^^^^^^^
12+
13+
error[E0308]: mismatched types
14+
--> $DIR/non-defining-method.rs:16:17
15+
|
16+
LL | type Bar<T> = impl Sized;
17+
| ---------- the expected opaque type
18+
LL | fn foo() -> Self::Bar<u32> {}
19+
| --- ^^^^^^^^^^^^^^ expected opaque type, found `()`
20+
| |
21+
| implicitly returns `()` as its body has no tail or `return` expression
22+
|
23+
= note: expected opaque type `<() as Foo>::Bar<u32>`
24+
found unit type `()`
25+
note: this item must have the opaque type in its signature in order to be able to register hidden types
26+
--> $DIR/non-defining-method.rs:16:8
27+
|
28+
LL | fn foo() -> Self::Bar<u32> {}
29+
| ^^^
30+
31+
error: aborting due to 2 previous errors
32+
33+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)