refactor pat parser method names/doc-comments to agree with RFC 3637
This commit is contained in:
parent
f8e50d8736
commit
35bbc45f16
5 changed files with 23 additions and 22 deletions
|
@ -990,7 +990,7 @@ pub fn parse_ast_fragment<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AstFragmentKind::Ty => AstFragment::Ty(this.parse_ty()?),
|
AstFragmentKind::Ty => AstFragment::Ty(this.parse_ty()?),
|
||||||
AstFragmentKind::Pat => AstFragment::Pat(this.parse_pat_allow_top_alt(
|
AstFragmentKind::Pat => AstFragment::Pat(this.parse_pat_no_top_guard(
|
||||||
None,
|
None,
|
||||||
RecoverComma::No,
|
RecoverComma::No,
|
||||||
RecoverColon::Yes,
|
RecoverColon::Yes,
|
||||||
|
|
|
@ -2630,7 +2630,7 @@ impl<'a> Parser<'a> {
|
||||||
};
|
};
|
||||||
self.bump(); // Eat `let` token
|
self.bump(); // Eat `let` token
|
||||||
let lo = self.prev_token.span;
|
let lo = self.prev_token.span;
|
||||||
let pat = self.parse_pat_allow_top_alt(
|
let pat = self.parse_pat_no_top_guard(
|
||||||
None,
|
None,
|
||||||
RecoverComma::Yes,
|
RecoverComma::Yes,
|
||||||
RecoverColon::Yes,
|
RecoverColon::Yes,
|
||||||
|
@ -2776,7 +2776,7 @@ impl<'a> Parser<'a> {
|
||||||
};
|
};
|
||||||
// Try to parse the pattern `for ($PAT) in $EXPR`.
|
// Try to parse the pattern `for ($PAT) in $EXPR`.
|
||||||
let pat = match (
|
let pat = match (
|
||||||
self.parse_pat_allow_top_alt(
|
self.parse_pat_no_top_guard(
|
||||||
None,
|
None,
|
||||||
RecoverComma::Yes,
|
RecoverComma::Yes,
|
||||||
RecoverColon::Yes,
|
RecoverColon::Yes,
|
||||||
|
@ -3239,7 +3239,7 @@ impl<'a> Parser<'a> {
|
||||||
// then we should recover.
|
// then we should recover.
|
||||||
let mut snapshot = this.create_snapshot_for_diagnostic();
|
let mut snapshot = this.create_snapshot_for_diagnostic();
|
||||||
let pattern_follows = snapshot
|
let pattern_follows = snapshot
|
||||||
.parse_pat_allow_top_alt(
|
.parse_pat_no_top_guard(
|
||||||
None,
|
None,
|
||||||
RecoverComma::Yes,
|
RecoverComma::Yes,
|
||||||
RecoverColon::Yes,
|
RecoverColon::Yes,
|
||||||
|
@ -3315,7 +3315,7 @@ impl<'a> Parser<'a> {
|
||||||
if self.token == token::OpenDelim(Delimiter::Parenthesis) {
|
if self.token == token::OpenDelim(Delimiter::Parenthesis) {
|
||||||
// Detect and recover from `($pat if $cond) => $arm`.
|
// Detect and recover from `($pat if $cond) => $arm`.
|
||||||
let left = self.token.span;
|
let left = self.token.span;
|
||||||
match self.parse_pat_allow_top_alt(
|
match self.parse_pat_no_top_guard(
|
||||||
None,
|
None,
|
||||||
RecoverComma::Yes,
|
RecoverComma::Yes,
|
||||||
RecoverColon::Yes,
|
RecoverColon::Yes,
|
||||||
|
@ -3349,7 +3349,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Regular parser flow:
|
// Regular parser flow:
|
||||||
let pat = self.parse_pat_allow_top_alt(
|
let pat = self.parse_pat_no_top_guard(
|
||||||
None,
|
None,
|
||||||
RecoverComma::Yes,
|
RecoverComma::Yes,
|
||||||
RecoverColon::Yes,
|
RecoverColon::Yes,
|
||||||
|
|
|
@ -174,7 +174,7 @@ impl<'a> Parser<'a> {
|
||||||
NonterminalKind::Pat(pat_kind) => {
|
NonterminalKind::Pat(pat_kind) => {
|
||||||
NtPat(self.collect_tokens_no_attrs(|this| match pat_kind {
|
NtPat(self.collect_tokens_no_attrs(|this| match pat_kind {
|
||||||
PatParam { .. } => this.parse_pat_no_top_alt(None, None),
|
PatParam { .. } => this.parse_pat_no_top_alt(None, None),
|
||||||
PatWithOr => this.parse_pat_allow_top_alt(
|
PatWithOr => this.parse_pat_no_top_guard(
|
||||||
None,
|
None,
|
||||||
RecoverComma::No,
|
RecoverComma::No,
|
||||||
RecoverColon::No,
|
RecoverColon::No,
|
||||||
|
|
|
@ -97,9 +97,9 @@ pub enum PatternLocation {
|
||||||
impl<'a> Parser<'a> {
|
impl<'a> Parser<'a> {
|
||||||
/// Parses a pattern.
|
/// Parses a pattern.
|
||||||
///
|
///
|
||||||
/// Corresponds to `pat<no_top_alt>` in RFC 2535 and does not admit or-patterns
|
/// Corresponds to `PatternNoTopAlt` in RFC 3637 and does not admit or-patterns
|
||||||
/// at the top level. Used when parsing the parameters of lambda expressions,
|
/// or guard patterns at the top level. Used when parsing the parameters of lambda
|
||||||
/// functions, function pointers, and `pat` macro fragments.
|
/// expressions, functions, function pointers, and `pat_param` macro fragments.
|
||||||
pub fn parse_pat_no_top_alt(
|
pub fn parse_pat_no_top_alt(
|
||||||
&mut self,
|
&mut self,
|
||||||
expected: Option<Expected>,
|
expected: Option<Expected>,
|
||||||
|
@ -110,25 +110,26 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
/// Parses a pattern.
|
/// Parses a pattern.
|
||||||
///
|
///
|
||||||
/// Corresponds to `top_pat` in RFC 2535 and allows or-pattern at the top level.
|
/// Corresponds to `PatternNoTopGuard` in RFC 3637 and allows or-patterns, but not
|
||||||
/// Used for parsing patterns in all cases when `pat<no_top_alt>` is not used.
|
/// guard patterns, at the top level. Used for parsing patterns in `pat` fragments and
|
||||||
|
/// `let`, `if let`, and `while let` expressions.
|
||||||
///
|
///
|
||||||
/// Note that after the FCP in <https://github.com/rust-lang/rust/issues/81415>,
|
/// Note that after the FCP in <https://github.com/rust-lang/rust/issues/81415>,
|
||||||
/// a leading vert is allowed in nested or-patterns, too. This allows us to
|
/// a leading vert is allowed in nested or-patterns, too. This allows us to
|
||||||
/// simplify the grammar somewhat.
|
/// simplify the grammar somewhat.
|
||||||
pub fn parse_pat_allow_top_alt(
|
pub fn parse_pat_no_top_guard(
|
||||||
&mut self,
|
&mut self,
|
||||||
expected: Option<Expected>,
|
expected: Option<Expected>,
|
||||||
rc: RecoverComma,
|
rc: RecoverComma,
|
||||||
ra: RecoverColon,
|
ra: RecoverColon,
|
||||||
rt: CommaRecoveryMode,
|
rt: CommaRecoveryMode,
|
||||||
) -> PResult<'a, P<Pat>> {
|
) -> PResult<'a, P<Pat>> {
|
||||||
self.parse_pat_allow_top_alt_inner(expected, rc, ra, rt, None).map(|(pat, _)| pat)
|
self.parse_pat_no_top_guard_inner(expected, rc, ra, rt, None).map(|(pat, _)| pat)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the pattern and a bool indicating whether we recovered from a trailing vert (true =
|
/// Returns the pattern and a bool indicating whether we recovered from a trailing vert (true =
|
||||||
/// recovered).
|
/// recovered).
|
||||||
fn parse_pat_allow_top_alt_inner(
|
fn parse_pat_no_top_guard_inner(
|
||||||
&mut self,
|
&mut self,
|
||||||
expected: Option<Expected>,
|
expected: Option<Expected>,
|
||||||
rc: RecoverComma,
|
rc: RecoverComma,
|
||||||
|
@ -229,7 +230,7 @@ impl<'a> Parser<'a> {
|
||||||
// We use `parse_pat_allow_top_alt` regardless of whether we actually want top-level
|
// We use `parse_pat_allow_top_alt` regardless of whether we actually want top-level
|
||||||
// or-patterns so that we can detect when a user tries to use it. This allows us to print a
|
// or-patterns so that we can detect when a user tries to use it. This allows us to print a
|
||||||
// better error message.
|
// better error message.
|
||||||
let (pat, trailing_vert) = self.parse_pat_allow_top_alt_inner(
|
let (pat, trailing_vert) = self.parse_pat_no_top_guard_inner(
|
||||||
expected,
|
expected,
|
||||||
rc,
|
rc,
|
||||||
RecoverColon::No,
|
RecoverColon::No,
|
||||||
|
@ -696,7 +697,7 @@ impl<'a> Parser<'a> {
|
||||||
} else if self.check(&token::OpenDelim(Delimiter::Bracket)) {
|
} else if self.check(&token::OpenDelim(Delimiter::Bracket)) {
|
||||||
// Parse `[pat, pat,...]` as a slice pattern.
|
// Parse `[pat, pat,...]` as a slice pattern.
|
||||||
let (pats, _) = self.parse_delim_comma_seq(Delimiter::Bracket, |p| {
|
let (pats, _) = self.parse_delim_comma_seq(Delimiter::Bracket, |p| {
|
||||||
p.parse_pat_allow_top_alt(
|
p.parse_pat_no_top_guard(
|
||||||
None,
|
None,
|
||||||
RecoverComma::No,
|
RecoverComma::No,
|
||||||
RecoverColon::No,
|
RecoverColon::No,
|
||||||
|
@ -944,7 +945,7 @@ impl<'a> Parser<'a> {
|
||||||
let open_paren = self.token.span;
|
let open_paren = self.token.span;
|
||||||
|
|
||||||
let (fields, trailing_comma) = self.parse_paren_comma_seq(|p| {
|
let (fields, trailing_comma) = self.parse_paren_comma_seq(|p| {
|
||||||
p.parse_pat_allow_top_alt(
|
p.parse_pat_no_top_guard(
|
||||||
None,
|
None,
|
||||||
RecoverComma::No,
|
RecoverComma::No,
|
||||||
RecoverColon::No,
|
RecoverColon::No,
|
||||||
|
@ -1359,7 +1360,7 @@ impl<'a> Parser<'a> {
|
||||||
path: Path,
|
path: Path,
|
||||||
) -> PResult<'a, PatKind> {
|
) -> PResult<'a, PatKind> {
|
||||||
let (fields, _) = self.parse_paren_comma_seq(|p| {
|
let (fields, _) = self.parse_paren_comma_seq(|p| {
|
||||||
p.parse_pat_allow_top_alt(
|
p.parse_pat_no_top_guard(
|
||||||
None,
|
None,
|
||||||
RecoverComma::No,
|
RecoverComma::No,
|
||||||
RecoverColon::No,
|
RecoverColon::No,
|
||||||
|
@ -1394,7 +1395,7 @@ impl<'a> Parser<'a> {
|
||||||
self.parse_builtin(|self_, _lo, ident| {
|
self.parse_builtin(|self_, _lo, ident| {
|
||||||
Ok(match ident.name {
|
Ok(match ident.name {
|
||||||
// builtin#deref(PAT)
|
// builtin#deref(PAT)
|
||||||
sym::deref => Some(ast::PatKind::Deref(self_.parse_pat_allow_top_alt(
|
sym::deref => Some(ast::PatKind::Deref(self_.parse_pat_no_top_guard(
|
||||||
None,
|
None,
|
||||||
RecoverComma::Yes,
|
RecoverComma::Yes,
|
||||||
RecoverColon::Yes,
|
RecoverColon::Yes,
|
||||||
|
@ -1669,7 +1670,7 @@ impl<'a> Parser<'a> {
|
||||||
// Parsing a pattern of the form `fieldname: pat`.
|
// Parsing a pattern of the form `fieldname: pat`.
|
||||||
let fieldname = self.parse_field_name()?;
|
let fieldname = self.parse_field_name()?;
|
||||||
self.bump();
|
self.bump();
|
||||||
let pat = self.parse_pat_allow_top_alt(
|
let pat = self.parse_pat_no_top_guard(
|
||||||
None,
|
None,
|
||||||
RecoverComma::No,
|
RecoverComma::No,
|
||||||
RecoverColon::No,
|
RecoverColon::No,
|
||||||
|
|
|
@ -469,7 +469,7 @@ impl<'a> Parser<'a> {
|
||||||
PathStyle::Pat
|
PathStyle::Pat
|
||||||
if let Ok(_) = self
|
if let Ok(_) = self
|
||||||
.parse_paren_comma_seq(|p| {
|
.parse_paren_comma_seq(|p| {
|
||||||
p.parse_pat_allow_top_alt(
|
p.parse_pat_no_top_guard(
|
||||||
None,
|
None,
|
||||||
RecoverComma::No,
|
RecoverComma::No,
|
||||||
RecoverColon::No,
|
RecoverColon::No,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue