Skip to content

Commit 16fd95c

Browse files
Rollup merge of #88314 - spastorino:type-of-a-let-tait-test, r=oli-obk
Add type of a let tait test r? `@oli-obk` Related to #86727
2 parents 3eee91b + dbadab5 commit 16fd95c

File tree

4 files changed

+142
-0
lines changed

4 files changed

+142
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![feature(type_alias_impl_trait)]
2+
#![allow(dead_code)]
3+
4+
// FIXME This should compile, but it currently doesn't
5+
6+
use std::fmt::Debug;
7+
8+
type Foo = impl Debug;
9+
//~^ ERROR: could not find defining uses
10+
11+
fn foo1() -> u32 {
12+
let x: Foo = 22_u32;
13+
//~^ ERROR: mismatched types [E0308]
14+
x
15+
//~^ ERROR: mismatched types [E0308]
16+
}
17+
18+
fn foo2() -> u32 {
19+
let x: Foo = 22_u32;
20+
//~^ ERROR: mismatched types [E0308]
21+
let y: Foo = x;
22+
same_type((x, y));
23+
y
24+
//~^ ERROR: mismatched types [E0308]
25+
}
26+
27+
fn same_type<T>(x: (T, T)) {}
28+
29+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/type_of_a_let.rs:12:18
3+
|
4+
LL | type Foo = impl Debug;
5+
| ---------- the expected opaque type
6+
...
7+
LL | let x: Foo = 22_u32;
8+
| --- ^^^^^^ expected opaque type, found `u32`
9+
| |
10+
| expected due to this
11+
|
12+
= note: expected opaque type `impl Debug`
13+
found type `u32`
14+
15+
error[E0308]: mismatched types
16+
--> $DIR/type_of_a_let.rs:14:5
17+
|
18+
LL | type Foo = impl Debug;
19+
| ---------- the found opaque type
20+
...
21+
LL | fn foo1() -> u32 {
22+
| --- expected `u32` because of return type
23+
...
24+
LL | x
25+
| ^ expected `u32`, found opaque type
26+
|
27+
= note: expected type `u32`
28+
found opaque type `impl Debug`
29+
30+
error[E0308]: mismatched types
31+
--> $DIR/type_of_a_let.rs:19:18
32+
|
33+
LL | type Foo = impl Debug;
34+
| ---------- the expected opaque type
35+
...
36+
LL | let x: Foo = 22_u32;
37+
| --- ^^^^^^ expected opaque type, found `u32`
38+
| |
39+
| expected due to this
40+
|
41+
= note: expected opaque type `impl Debug`
42+
found type `u32`
43+
44+
error[E0308]: mismatched types
45+
--> $DIR/type_of_a_let.rs:23:5
46+
|
47+
LL | type Foo = impl Debug;
48+
| ---------- the found opaque type
49+
...
50+
LL | fn foo2() -> u32 {
51+
| --- expected `u32` because of return type
52+
...
53+
LL | y
54+
| ^ expected `u32`, found opaque type
55+
|
56+
= note: expected type `u32`
57+
found opaque type `impl Debug`
58+
59+
error: could not find defining uses
60+
--> $DIR/type_of_a_let.rs:8:12
61+
|
62+
LL | type Foo = impl Debug;
63+
| ^^^^^^^^^^
64+
65+
error: aborting due to 5 previous errors
66+
67+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(type_alias_impl_trait)]
2+
#![allow(dead_code)]
3+
4+
// FIXME This should be under a feature flag
5+
6+
use std::fmt::Debug;
7+
8+
fn foo1() -> u32 {
9+
let x: impl Debug = 22_u32;
10+
//~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562]
11+
x // ERROR: we only know x: Debug, we don't know x = u32
12+
}
13+
14+
fn foo2() -> u32 {
15+
let x: impl Debug = 22_u32;
16+
//~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562]
17+
let y: impl Debug = x;
18+
//~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562]
19+
same_type((x, y)); // ERROR
20+
x
21+
}
22+
23+
fn same_type<T>(x: (T, T)) {}
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/type_of_a_let2.rs:9:12
3+
|
4+
LL | let x: impl Debug = 22_u32;
5+
| ^^^^^^^^^^
6+
7+
error[E0562]: `impl Trait` not allowed outside of function and method return types
8+
--> $DIR/type_of_a_let2.rs:15:12
9+
|
10+
LL | let x: impl Debug = 22_u32;
11+
| ^^^^^^^^^^
12+
13+
error[E0562]: `impl Trait` not allowed outside of function and method return types
14+
--> $DIR/type_of_a_let2.rs:17:12
15+
|
16+
LL | let y: impl Debug = x;
17+
| ^^^^^^^^^^
18+
19+
error: aborting due to 3 previous errors
20+
21+
For more information about this error, try `rustc --explain E0562`.

0 commit comments

Comments
 (0)