File tree Expand file tree Collapse file tree 3 files changed +15
-6
lines changed Expand file tree Collapse file tree 3 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -6,8 +6,14 @@ use crate::ty::{ReturnType, Type};
6
6
use proc_macro2:: { Delimiter , TokenStream , TokenTree } ;
7
7
use std:: ops:: ControlFlow ;
8
8
9
- pub ( crate ) fn requires_terminator ( expr : & Expr ) -> bool {
10
- // see https://github.com/rust-lang/rust/blob/9a19e7604/compiler/rustc_ast/src/util/classify.rs#L7-L26
9
+ pub ( crate ) fn requires_semi_to_be_stmt ( expr : & Expr ) -> bool {
10
+ match expr {
11
+ Expr :: Macro ( expr) => !expr. mac . delimiter . is_brace ( ) ,
12
+ _ => requires_comma_to_be_match_arm ( expr) ,
13
+ }
14
+ }
15
+
16
+ pub ( crate ) fn requires_comma_to_be_match_arm ( expr : & Expr ) -> bool {
11
17
match expr {
12
18
Expr :: If ( _)
13
19
| Expr :: Match ( _)
Original file line number Diff line number Diff line change @@ -2873,7 +2873,7 @@ pub(crate) mod parsing {
2873
2873
fat_arrow_token : input. parse ( ) ?,
2874
2874
body : {
2875
2875
let body = Expr :: parse_with_earlier_boundary_rule ( input) ?;
2876
- requires_comma = classify:: requires_terminator ( & body) ;
2876
+ requires_comma = classify:: requires_comma_to_be_match_arm ( & body) ;
2877
2877
Box :: new ( body)
2878
2878
} ,
2879
2879
comma : {
@@ -3312,7 +3312,10 @@ pub(crate) mod printing {
3312
3312
// Ensure that we have a comma after a non-block arm, except
3313
3313
// for the last one.
3314
3314
let is_last = i == self . arms . len ( ) - 1 ;
3315
- if !is_last && classify:: requires_terminator ( & arm. body ) && arm. comma . is_none ( ) {
3315
+ if !is_last
3316
+ && classify:: requires_comma_to_be_match_arm ( & arm. body )
3317
+ && arm. comma . is_none ( )
3318
+ {
3316
3319
<Token ! [ , ] >:: default ( ) . to_tokens ( tokens) ;
3317
3320
}
3318
3321
}
Original file line number Diff line number Diff line change @@ -159,7 +159,7 @@ pub(crate) mod parsing {
159
159
}
160
160
let stmt = parse_stmt ( input, AllowNoSemi ( true ) ) ?;
161
161
let requires_semicolon = match & stmt {
162
- Stmt :: Expr ( stmt, None ) => classify:: requires_terminator ( stmt) ,
162
+ Stmt :: Expr ( stmt, None ) => classify:: requires_semi_to_be_stmt ( stmt) ,
163
163
Stmt :: Macro ( stmt) => {
164
164
stmt. semi_token . is_none ( ) && !stmt. mac . delimiter . is_brace ( )
165
165
}
@@ -401,7 +401,7 @@ pub(crate) mod parsing {
401
401
402
402
if semi_token. is_some ( ) {
403
403
Ok ( Stmt :: Expr ( e, semi_token) )
404
- } else if allow_nosemi. 0 || !classify:: requires_terminator ( & e) {
404
+ } else if allow_nosemi. 0 || !classify:: requires_semi_to_be_stmt ( & e) {
405
405
Ok ( Stmt :: Expr ( e, None ) )
406
406
} else {
407
407
Err ( input. error ( "expected semicolon" ) )
You can’t perform that action at this time.
0 commit comments