forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#82714 - estebank:missing-braces, r=oli-obk
Detect match arm body without braces Fix rust-lang#82524.
- Loading branch information
Showing
4 changed files
with
334 additions
and
1 deletion.
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
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
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,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, | ||
} | ||
} |
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,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 | ||
|