Skip to content

Commit

Permalink
Add test for type mismatch on first match arm
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Feb 8, 2019
1 parent 9e934e2 commit 7eb6a2a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/test/ui/match/match-type-err-first-arm.rs
@@ -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
}
31 changes: 31 additions & 0 deletions src/test/ui/match/match-type-err-first-arm.stderr
@@ -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`.

0 comments on commit 7eb6a2a

Please sign in to comment.