about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-02-07 16:12:12 -0800
committerEsteban Küber <esteban@kuber.com.ar>2019-02-07 16:12:12 -0800
commit7eb6a2a9729dd0f948fc30e391e32c0a51d3d0a7 (patch)
tree79c0066ffa11c04546365346e4d2aa134e3c3485 /src
parent9e934e22151d5589cbe3cb1193250d8ac0b366fb (diff)
downloadrust-7eb6a2a9729dd0f948fc30e391e32c0a51d3d0a7.tar.gz
rust-7eb6a2a9729dd0f948fc30e391e32c0a51d3d0a7.zip
Add test for type mismatch on first match arm
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/match/match-type-err-first-arm.rs27
-rw-r--r--src/test/ui/match/match-type-err-first-arm.stderr31
2 files changed, 58 insertions, 0 deletions
diff --git a/src/test/ui/match/match-type-err-first-arm.rs b/src/test/ui/match/match-type-err-first-arm.rs
new file mode 100644
index 00000000000..31fa50d2b45
--- /dev/null
+++ b/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
+}
diff --git a/src/test/ui/match/match-type-err-first-arm.stderr b/src/test/ui/match/match-type-err-first-arm.stderr
new file mode 100644
index 00000000000..8f722343a58
--- /dev/null
+++ b/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`.