Skip to content

Commit 9171ba2

Browse files
committed
add a test for tuple coercions
1 parent 779e19d commit 9171ba2

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

tests/ui/tuple/coercion.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This test checks if tuple elements are a coercion site or not.
2+
// Note that the code here is a degenerate case, but you can get similar effects in real code, when
3+
// unifying match arms, for example.
4+
5+
fn main() {
6+
let _: ((),) = (loop {},);
7+
8+
((),) = (loop {},); //~ error: mismatched types
9+
10+
let x = (loop {},);
11+
let _: ((),) = x; //~ error: mismatched types
12+
13+
let _: (&[u8],) = (&[],);
14+
15+
let y = (&[],);
16+
let _: (&[u8],) = y; //~ error: mismatched types
17+
}

tests/ui/tuple/coercion.stderr

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/coercion.rs:8:6
3+
|
4+
LL | ((),) = (loop {},);
5+
| ^^ ---------- this expression has type `(!,)`
6+
| |
7+
| expected `!`, found `()`
8+
|
9+
= note: expected type `!`
10+
found unit type `()`
11+
12+
error[E0308]: mismatched types
13+
--> $DIR/coercion.rs:11:20
14+
|
15+
LL | let _: ((),) = x;
16+
| ----- ^ expected `((),)`, found `(!,)`
17+
| |
18+
| expected due to this
19+
|
20+
= note: expected tuple `((),)`
21+
found tuple `(!,)`
22+
23+
error[E0308]: mismatched types
24+
--> $DIR/coercion.rs:16:23
25+
|
26+
LL | let _: (&[u8],) = y;
27+
| -------- ^ expected `(&[u8],)`, found `(&[_; 0],)`
28+
| |
29+
| expected due to this
30+
|
31+
= note: expected tuple `(&[u8],)`
32+
found tuple `(&[_; 0],)`
33+
34+
error: aborting due to 3 previous errors
35+
36+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)