Skip to content

Commit 95e4a92

Browse files
committed
add a test for tuple coercions
1 parent 779e19d commit 95e4a92

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

tests/ui/tuple/coercion-never.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
// See also coercion-slice.rs
6+
7+
fn main() {
8+
let _: ((),) = (loop {},);
9+
10+
((),) = (loop {},); //~ error: mismatched types
11+
12+
let x = (loop {},);
13+
let _: ((),) = x; //~ error: mismatched types
14+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/coercion-never.rs:10: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-never.rs:13: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: aborting due to 2 previous errors
24+
25+
For more information about this error, try `rustc --explain E0308`.

tests/ui/tuple/coercion-slice.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
// See also: coercion-never.rs
6+
7+
fn main() {
8+
let _: (&[u8],) = (&[],);
9+
10+
let y = (&[],);
11+
let _: (&[u8],) = y; //~ error: mismatched types
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/coercion-slice.rs:11:23
3+
|
4+
LL | let _: (&[u8],) = y;
5+
| -------- ^ expected `(&[u8],)`, found `(&[_; 0],)`
6+
| |
7+
| expected due to this
8+
|
9+
= note: expected tuple `(&[u8],)`
10+
found tuple `(&[_; 0],)`
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)