about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-03-05 21:44:39 +0100
committerGitHub <noreply@github.com>2021-03-05 21:44:39 +0100
commit34b2caa79f4451ff7eede9a578295e1a48db4bf2 (patch)
tree40012ecff7e8af0873cb7b07c3c7ac437e38e6fc /src
parent8867f7f6507ad0a6682c969235fb5f0b572e646b (diff)
parentae494d147af627537097f10f21cf961e4c1c6f38 (diff)
downloadrust-34b2caa79f4451ff7eede9a578295e1a48db4bf2.tar.gz
rust-34b2caa79f4451ff7eede9a578295e1a48db4bf2.zip
Rollup merge of #82714 - estebank:missing-braces, r=oli-obk
Detect match arm body without braces

Fix #82524.
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/parser/match-arm-without-braces.rs87
-rw-r--r--src/test/ui/parser/match-arm-without-braces.stderr135
2 files changed, 222 insertions, 0 deletions
diff --git a/src/test/ui/parser/match-arm-without-braces.rs b/src/test/ui/parser/match-arm-without-braces.rs
new file mode 100644
index 00000000000..55a88742769
--- /dev/null
+++ b/src/test/ui/parser/match-arm-without-braces.rs
@@ -0,0 +1,87 @@
+struct S;
+
+impl S {
+    fn get<K, V: Default>(_: K) -> Option<V> {
+        Default::default()
+    }
+}
+
+enum Val {
+    Foo,
+    Bar,
+}
+
+impl Default for Val {
+    fn default() -> Self {
+        Val::Foo
+    }
+}
+
+fn main() {
+    match S::get(1) {
+        Some(Val::Foo) => {}
+        _ => {}
+    }
+    match S::get(2) {
+        Some(Val::Foo) => 3; //~ ERROR `match` arm body without braces
+        _ => 4,
+    }
+    match S::get(5) {
+        Some(Val::Foo) =>
+          7; //~ ERROR `match` arm body without braces
+          8;
+        _ => 9,
+    }
+    match S::get(10) {
+        Some(Val::Foo) =>
+          11; //~ ERROR `match` arm body without braces
+          12;
+        _ => (),
+    }
+    match S::get(13) {
+        None => {}
+        Some(Val::Foo) =>
+          14; //~ ERROR `match` arm body without braces
+          15;
+    }
+    match S::get(16) {
+        Some(Val::Foo) => 17
+        _ => 18, //~ ERROR expected one of
+    }
+    match S::get(19) {
+        Some(Val::Foo) =>
+          20; //~ ERROR `match` arm body without braces
+          21
+        _ => 22,
+    }
+    match S::get(23) {
+        Some(Val::Foo) =>
+          24; //~ ERROR `match` arm body without braces
+          25
+        _ => (),
+    }
+    match S::get(26) {
+        None => {}
+        Some(Val::Foo) =>
+          27; //~ ERROR `match` arm body without braces
+          28
+    }
+    match S::get(29) {
+        Some(Val::Foo) =>
+          30; //~ ERROR expected one of
+          31,
+        _ => 32,
+    }
+    match S::get(33) {
+        Some(Val::Foo) =>
+          34; //~ ERROR expected one of
+          35,
+        _ => (),
+    }
+    match S::get(36) {
+        None => {}
+        Some(Val::Foo) =>
+          37; //~ ERROR expected one of
+          38,
+    }
+}
diff --git a/src/test/ui/parser/match-arm-without-braces.stderr b/src/test/ui/parser/match-arm-without-braces.stderr
new file mode 100644
index 00000000000..03ae351bf79
--- /dev/null
+++ b/src/test/ui/parser/match-arm-without-braces.stderr
@@ -0,0 +1,135 @@
+error: `match` arm body without braces
+  --> $DIR/match-arm-without-braces.rs:26:27
+   |
+LL |         Some(Val::Foo) => 3;
+   |                        -- ^- help: use a comma to end a `match` arm expression: `,`
+   |                        |  |
+   |                        |  this statement is not surrounded by a body
+   |                        while parsing the `match` arm starting here
+
+error: `match` arm body without braces
+  --> $DIR/match-arm-without-braces.rs:31:11
+   |
+LL |           Some(Val::Foo) =>
+   |                          -- while parsing the `match` arm starting here
+LL | /           7;
+LL | |           8;
+   | |____________^ these statements are not surrounded by a body
+   |
+help: surround the statements with a body
+   |
+LL |           { 7;
+LL |           8; }
+   |
+
+error: `match` arm body without braces
+  --> $DIR/match-arm-without-braces.rs:37:11
+   |
+LL |           Some(Val::Foo) =>
+   |                          -- while parsing the `match` arm starting here
+LL | /           11;
+LL | |           12;
+   | |_____________^ these statements are not surrounded by a body
+   |
+help: surround the statements with a body
+   |
+LL |           { 11;
+LL |           12; }
+   |
+
+error: `match` arm body without braces
+  --> $DIR/match-arm-without-braces.rs:44:11
+   |
+LL |           Some(Val::Foo) =>
+   |                          -- while parsing the `match` arm starting here
+LL | /           14;
+LL | |           15;
+   | |_____________^ these statements are not surrounded by a body
+   |
+help: surround the statements with a body
+   |
+LL |           { 14;
+LL |           15; }
+   |
+
+error: expected one of `,`, `.`, `?`, `}`, or an operator, found reserved identifier `_`
+  --> $DIR/match-arm-without-braces.rs:49:9
+   |
+LL |         Some(Val::Foo) => 17
+   |                        --   - expected one of `,`, `.`, `?`, `}`, or an operator
+   |                        |
+   |                        while parsing the `match` arm starting here
+LL |         _ => 18,
+   |         ^ unexpected token
+
+error: `match` arm body without braces
+  --> $DIR/match-arm-without-braces.rs:53:11
+   |
+LL |           Some(Val::Foo) =>
+   |                          -- while parsing the `match` arm starting here
+LL | /           20;
+LL | |           21
+   | |____________^ these statements are not surrounded by a body
+   |
+help: surround the statements with a body
+   |
+LL |           { 20;
+LL |           21 }
+   |
+
+error: `match` arm body without braces
+  --> $DIR/match-arm-without-braces.rs:59:11
+   |
+LL |           Some(Val::Foo) =>
+   |                          -- while parsing the `match` arm starting here
+LL | /           24;
+LL | |           25
+   | |____________^ these statements are not surrounded by a body
+   |
+help: surround the statements with a body
+   |
+LL |           { 24;
+LL |           25 }
+   |
+
+error: `match` arm body without braces
+  --> $DIR/match-arm-without-braces.rs:66:11
+   |
+LL |           Some(Val::Foo) =>
+   |                          -- while parsing the `match` arm starting here
+LL | /           27;
+LL | |           28
+   | |____________^ these statements are not surrounded by a body
+   |
+help: surround the statements with a body
+   |
+LL |           { 27;
+LL |           28 }
+   |
+
+error: expected one of `,`, `.`, `?`, `}`, or an operator, found `;`
+  --> $DIR/match-arm-without-braces.rs:71:13
+   |
+LL |         Some(Val::Foo) =>
+   |                        -- while parsing the `match` arm starting here
+LL |           30;
+   |             ^ expected one of `,`, `.`, `?`, `}`, or an operator
+
+error: expected one of `,`, `.`, `?`, `}`, or an operator, found `;`
+  --> $DIR/match-arm-without-braces.rs:77:13
+   |
+LL |         Some(Val::Foo) =>
+   |                        -- while parsing the `match` arm starting here
+LL |           34;
+   |             ^ expected one of `,`, `.`, `?`, `}`, or an operator
+
+error: expected one of `,`, `.`, `?`, `}`, or an operator, found `;`
+  --> $DIR/match-arm-without-braces.rs:84:13
+   |
+LL |         Some(Val::Foo) =>
+   |                        -- while parsing the `match` arm starting here
+LL |           37;
+   |             ^ expected one of `,`, `.`, `?`, `}`, or an operator
+
+error: aborting due to 11 previous errors
+