Add test for type mismatch on first match arm

This commit is contained in:
Esteban Küber 2019-02-07 16:12:12 -08:00
parent 9e934e2215
commit 7eb6a2a972
2 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,27 @@
fn main() {
let _ = test_func1(1);
let _ = test_func2(1);
}
fn test_func1(n: i32) -> i32 {
//~^ NOTE expected `i32` because of return type
match n {
12 => 'b',
//~^ ERROR mismatched types
//~| NOTE expected i32, found char
_ => 42,
}
}
fn test_func2(n: i32) -> i32 {
let x = match n {
//~^ NOTE `match` arms have incompatible types
12 => 'b',
//~^ NOTE this is found to be of type `char`
_ => 42,
//~^ ERROR match arms have incompatible types
//~| NOTE expected char, found integer
//~| NOTE expected type `char`
};
x
}

View file

@ -0,0 +1,31 @@
error[E0308]: mismatched types
--> $DIR/match-type-err-first-arm.rs:9:15
|
LL | fn test_func1(n: i32) -> i32 {
| --- expected `i32` because of return type
...
LL | 12 => 'b',
| ^^^ expected i32, found char
error[E0308]: match arms have incompatible types
--> $DIR/match-type-err-first-arm.rs:21:14
|
LL | let x = match n {
| _____________-
LL | | //~^ NOTE `match` arms have incompatible types
LL | | 12 => 'b',
| | --- this is found to be of type `char`
LL | | //~^ NOTE this is found to be of type `char`
LL | | _ => 42,
| | ^^ expected char, found integer
... |
LL | | //~| NOTE expected type `char`
LL | | };
| |_____- `match` arms have incompatible types
|
= note: expected type `char`
found type `{integer}`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.