diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-04-26 15:21:15 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-04-27 08:15:12 +1000 |
| commit | 6b367a05320f2792414281075a4e98452b412a82 (patch) | |
| tree | 21cfd9119b61276cbdaf8f754f8e2bf7b451b2ec /compiler/rustc_parse | |
| parent | f0bbc782ac11de6001eeec63e347427dbc639c04 (diff) | |
| download | rust-6b367a05320f2792414281075a4e98452b412a82.tar.gz rust-6b367a05320f2792414281075a4e98452b412a82.zip | |
Avoid producing `NoDelim` values in `MacArgs::delim()`.
Diffstat (limited to 'compiler/rustc_parse')
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 5b7ae5f7a7b..14f1208b71f 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -164,25 +164,29 @@ impl<'a> Parser<'a> { let delim = args.delim(); let hi = self.prev_token.span; - let style = - if delim == token::Brace { MacStmtStyle::Braces } else { MacStmtStyle::NoBraces }; + let style = match delim { + Some(token::Brace) => MacStmtStyle::Braces, + Some(_) => MacStmtStyle::NoBraces, + None => unreachable!(), + }; let mac = MacCall { path, args, prior_type_ascription: self.last_type_ascription }; - let kind = - if (delim == token::Brace && self.token != token::Dot && self.token != token::Question) - || self.token == token::Semi - || self.token == token::Eof - { - StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None })) - } else { - // Since none of the above applied, this is an expression statement macro. - let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac), AttrVec::new()); - let e = self.maybe_recover_from_bad_qpath(e, true)?; - let e = self.parse_dot_or_call_expr_with(e, lo, attrs.into())?; - let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?; - StmtKind::Expr(e) - }; + let kind = if (style == MacStmtStyle::Braces + && self.token != token::Dot + && self.token != token::Question) + || self.token == token::Semi + || self.token == token::Eof + { + StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None })) + } else { + // Since none of the above applied, this is an expression statement macro. + let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac), AttrVec::new()); + let e = self.maybe_recover_from_bad_qpath(e, true)?; + let e = self.parse_dot_or_call_expr_with(e, lo, attrs.into())?; + let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?; + StmtKind::Expr(e) + }; Ok(self.mk_stmt(lo.to(hi), kind)) } |
