Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for type mismatch on first match arm
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |