about summary refs log tree commit diff
path: root/tests/ui/parser/missing-fat-arrow.rs
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2023-10-03 21:21:02 +0000
committerEsteban Küber <esteban@kuber.com.ar>2023-10-03 21:21:02 +0000
commit745c1ea4388864d6a832aeacb9fc3b9db1ab9c2f (patch)
tree75c968f15f07493db47d6ca1cac463be4fe9bfe7 /tests/ui/parser/missing-fat-arrow.rs
parenta6dfd89fa76e5dda36d07463d0e54268d6240b49 (diff)
downloadrust-745c1ea4388864d6a832aeacb9fc3b9db1ab9c2f.tar.gz
rust-745c1ea4388864d6a832aeacb9fc3b9db1ab9c2f.zip
Detect missing `=>` after match guard during parsing
```
error: expected one of `,`, `:`, or `}`, found `.`
  --> $DIR/missing-fat-arrow.rs:25:14
   |
LL |         Some(a) if a.value == b {
   |                               - while parsing this struct
LL |             a.value = 1;
   |             -^ expected one of `,`, `:`, or `}`
   |             |
   |             while parsing this struct field
   |
help: try naming a field
   |
LL |             a: a.value = 1;
   |             ++
help: you might have meant to start a match arm after the match guard
   |
LL |         Some(a) if a.value == b => {
   |                                 ++
```

Fix #78585.
Diffstat (limited to 'tests/ui/parser/missing-fat-arrow.rs')
-rw-r--r--tests/ui/parser/missing-fat-arrow.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/ui/parser/missing-fat-arrow.rs b/tests/ui/parser/missing-fat-arrow.rs
new file mode 100644
index 00000000000..fef16129cd0
--- /dev/null
+++ b/tests/ui/parser/missing-fat-arrow.rs
@@ -0,0 +1,41 @@
+fn main() {
+    let x = 1;
+    let y = 2;
+    let value = 3;
+
+    match value {
+        Some(x) if x == y {
+            self.next_token()?; //~ ERROR expected identifier, found keyword `self`
+            Ok(true)
+        },
+        _ => {
+            Ok(false)
+        }
+    }
+    let _: i32 = (); //~ ERROR mismatched types
+}
+
+struct Foo {
+    value: usize
+}
+
+fn foo(a: Option<&mut Foo>, b: usize) {
+    match a {
+        Some(a) if a.value == b {
+            a.value = 1; //~ ERROR expected one of `,`, `:`, or `}`, found `.`
+        },
+        _ => {}
+    }
+    let _: i32 = (); //~ ERROR mismatched types
+}
+
+fn bar(a: Option<&mut Foo>, b: usize) {
+    match a {
+        Some(a) if a.value == b {
+            a.value, //~ ERROR expected one of `,`, `:`, or `}`, found `.`
+        } => {
+        }
+        _ => {}
+    }
+    let _: i32 = (); //~ ERROR mismatched types
+}