Skip to content

Commit 7eb6a2a

Browse files
committed
Add test for type mismatch on first match arm
1 parent 9e934e2 commit 7eb6a2a

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
fn main() {
2+
let _ = test_func1(1);
3+
let _ = test_func2(1);
4+
}
5+
6+
fn test_func1(n: i32) -> i32 {
7+
//~^ NOTE expected `i32` because of return type
8+
match n {
9+
12 => 'b',
10+
//~^ ERROR mismatched types
11+
//~| NOTE expected i32, found char
12+
_ => 42,
13+
}
14+
}
15+
16+
fn test_func2(n: i32) -> i32 {
17+
let x = match n {
18+
//~^ NOTE `match` arms have incompatible types
19+
12 => 'b',
20+
//~^ NOTE this is found to be of type `char`
21+
_ => 42,
22+
//~^ ERROR match arms have incompatible types
23+
//~| NOTE expected char, found integer
24+
//~| NOTE expected type `char`
25+
};
26+
x
27+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/match-type-err-first-arm.rs:9:15
3+
|
4+
LL | fn test_func1(n: i32) -> i32 {
5+
| --- expected `i32` because of return type
6+
...
7+
LL | 12 => 'b',
8+
| ^^^ expected i32, found char
9+
10+
error[E0308]: match arms have incompatible types
11+
--> $DIR/match-type-err-first-arm.rs:21:14
12+
|
13+
LL | let x = match n {
14+
| _____________-
15+
LL | | //~^ NOTE `match` arms have incompatible types
16+
LL | | 12 => 'b',
17+
| | --- this is found to be of type `char`
18+
LL | | //~^ NOTE this is found to be of type `char`
19+
LL | | _ => 42,
20+
| | ^^ expected char, found integer
21+
... |
22+
LL | | //~| NOTE expected type `char`
23+
LL | | };
24+
| |_____- `match` arms have incompatible types
25+
|
26+
= note: expected type `char`
27+
found type `{integer}`
28+
29+
error: aborting due to 2 previous errors
30+
31+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)