Skip to content

Commit e32bd69

Browse files
committed
extract parse_pat_mac_invoc
1 parent 231da7e commit e32bd69

File tree

1 file changed

+17
-14
lines changed
  • src/libsyntax/parse/parser

1 file changed

+17
-14
lines changed

src/libsyntax/parse/parser/pat.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::{Parser, PResult, PathStyle};
33
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
44
use crate::ptr::P;
55
use crate::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac_};
6-
use crate::ast::{BindingMode, Ident, Mutability, Expr, ExprKind};
6+
use crate::ast::{BindingMode, Ident, Mutability, Path, Expr, ExprKind};
77
use crate::parse::token::{self};
88
use crate::print::pprust;
99
use crate::source_map::{respan, Span, Spanned};
@@ -165,18 +165,7 @@ impl<'a> Parser<'a> {
165165
(None, self.parse_path(PathStyle::Expr)?)
166166
};
167167
match self.token.kind {
168-
token::Not if qself.is_none() => {
169-
// Parse macro invocation
170-
self.bump();
171-
let (delim, tts) = self.expect_delimited_token_tree()?;
172-
let mac = respan(lo.to(self.prev_span), Mac_ {
173-
path,
174-
tts,
175-
delim,
176-
prior_type_ascription: self.last_type_ascription,
177-
});
178-
PatKind::Mac(mac)
179-
}
168+
token::Not if qself.is_none() => self.parse_pat_mac_invoc(lo, path)?,
180169
token::DotDotDot | token::DotDotEq | token::DotDot => {
181170
let (end_kind, form) = match self.token.kind {
182171
token::DotDot => (RangeEnd::Excluded, ".."),
@@ -328,7 +317,8 @@ impl<'a> Parser<'a> {
328317
})
329318
}
330319

331-
// Recover on `mut ref? ident @ pat` and suggest that the order of `mut` and `ref` is incorrect.
320+
/// Recover on `mut ref? ident @ pat` and suggest
321+
/// that the order of `mut` and `ref` is incorrect.
332322
fn recover_pat_ident_mut_first(&mut self) -> PResult<'a, PatKind> {
333323
let mutref_span = self.prev_span.to(self.token.span);
334324
let binding_mode = if self.eat_keyword(kw::Ref) {
@@ -347,6 +337,19 @@ impl<'a> Parser<'a> {
347337
self.parse_pat_ident(binding_mode)
348338
}
349339

340+
/// Parse macro invocation
341+
fn parse_pat_mac_invoc(&mut self, lo: Span, path: Path) -> PResult<'a, PatKind> {
342+
self.bump();
343+
let (delim, tts) = self.expect_delimited_token_tree()?;
344+
let mac = respan(lo.to(self.prev_span), Mac_ {
345+
path,
346+
tts,
347+
delim,
348+
prior_type_ascription: self.last_type_ascription,
349+
});
350+
Ok(PatKind::Mac(mac))
351+
}
352+
350353
// Helper function to decide whether to parse as ident binding
351354
// or to try to do something more complex like range patterns.
352355
fn parse_as_ident(&mut self) -> bool {

0 commit comments

Comments
 (0)