Skip to content

Commit 35bbc45

Browse files
max-niedermanNadrieril
authored andcommitted
refactor pat parser method names/doc-comments to agree with RFC 3637
1 parent f8e50d8 commit 35bbc45

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

compiler/rustc_expand/src/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ pub fn parse_ast_fragment<'a>(
990990
}
991991
}
992992
AstFragmentKind::Ty => AstFragment::Ty(this.parse_ty()?),
993-
AstFragmentKind::Pat => AstFragment::Pat(this.parse_pat_allow_top_alt(
993+
AstFragmentKind::Pat => AstFragment::Pat(this.parse_pat_no_top_guard(
994994
None,
995995
RecoverComma::No,
996996
RecoverColon::Yes,

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,7 @@ impl<'a> Parser<'a> {
26302630
};
26312631
self.bump(); // Eat `let` token
26322632
let lo = self.prev_token.span;
2633-
let pat = self.parse_pat_allow_top_alt(
2633+
let pat = self.parse_pat_no_top_guard(
26342634
None,
26352635
RecoverComma::Yes,
26362636
RecoverColon::Yes,
@@ -2776,7 +2776,7 @@ impl<'a> Parser<'a> {
27762776
};
27772777
// Try to parse the pattern `for ($PAT) in $EXPR`.
27782778
let pat = match (
2779-
self.parse_pat_allow_top_alt(
2779+
self.parse_pat_no_top_guard(
27802780
None,
27812781
RecoverComma::Yes,
27822782
RecoverColon::Yes,
@@ -3239,7 +3239,7 @@ impl<'a> Parser<'a> {
32393239
// then we should recover.
32403240
let mut snapshot = this.create_snapshot_for_diagnostic();
32413241
let pattern_follows = snapshot
3242-
.parse_pat_allow_top_alt(
3242+
.parse_pat_no_top_guard(
32433243
None,
32443244
RecoverComma::Yes,
32453245
RecoverColon::Yes,
@@ -3315,7 +3315,7 @@ impl<'a> Parser<'a> {
33153315
if self.token == token::OpenDelim(Delimiter::Parenthesis) {
33163316
// Detect and recover from `($pat if $cond) => $arm`.
33173317
let left = self.token.span;
3318-
match self.parse_pat_allow_top_alt(
3318+
match self.parse_pat_no_top_guard(
33193319
None,
33203320
RecoverComma::Yes,
33213321
RecoverColon::Yes,
@@ -3349,7 +3349,7 @@ impl<'a> Parser<'a> {
33493349
}
33503350
} else {
33513351
// Regular parser flow:
3352-
let pat = self.parse_pat_allow_top_alt(
3352+
let pat = self.parse_pat_no_top_guard(
33533353
None,
33543354
RecoverComma::Yes,
33553355
RecoverColon::Yes,

compiler/rustc_parse/src/parser/nonterminal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl<'a> Parser<'a> {
174174
NonterminalKind::Pat(pat_kind) => {
175175
NtPat(self.collect_tokens_no_attrs(|this| match pat_kind {
176176
PatParam { .. } => this.parse_pat_no_top_alt(None, None),
177-
PatWithOr => this.parse_pat_allow_top_alt(
177+
PatWithOr => this.parse_pat_no_top_guard(
178178
None,
179179
RecoverComma::No,
180180
RecoverColon::No,

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ pub enum PatternLocation {
9797
impl<'a> Parser<'a> {
9898
/// Parses a pattern.
9999
///
100-
/// Corresponds to `pat<no_top_alt>` in RFC 2535 and does not admit or-patterns
101-
/// at the top level. Used when parsing the parameters of lambda expressions,
102-
/// functions, function pointers, and `pat` macro fragments.
100+
/// Corresponds to `PatternNoTopAlt` in RFC 3637 and does not admit or-patterns
101+
/// or guard patterns at the top level. Used when parsing the parameters of lambda
102+
/// expressions, functions, function pointers, and `pat_param` macro fragments.
103103
pub fn parse_pat_no_top_alt(
104104
&mut self,
105105
expected: Option<Expected>,
@@ -110,25 +110,26 @@ impl<'a> Parser<'a> {
110110

111111
/// Parses a pattern.
112112
///
113-
/// Corresponds to `top_pat` in RFC 2535 and allows or-pattern at the top level.
114-
/// Used for parsing patterns in all cases when `pat<no_top_alt>` is not used.
113+
/// Corresponds to `PatternNoTopGuard` in RFC 3637 and allows or-patterns, but not
114+
/// guard patterns, at the top level. Used for parsing patterns in `pat` fragments and
115+
/// `let`, `if let`, and `while let` expressions.
115116
///
116117
/// Note that after the FCP in <https://github.com/rust-lang/rust/issues/81415>,
117118
/// a leading vert is allowed in nested or-patterns, too. This allows us to
118119
/// simplify the grammar somewhat.
119-
pub fn parse_pat_allow_top_alt(
120+
pub fn parse_pat_no_top_guard(
120121
&mut self,
121122
expected: Option<Expected>,
122123
rc: RecoverComma,
123124
ra: RecoverColon,
124125
rt: CommaRecoveryMode,
125126
) -> PResult<'a, P<Pat>> {
126-
self.parse_pat_allow_top_alt_inner(expected, rc, ra, rt, None).map(|(pat, _)| pat)
127+
self.parse_pat_no_top_guard_inner(expected, rc, ra, rt, None).map(|(pat, _)| pat)
127128
}
128129

129130
/// Returns the pattern and a bool indicating whether we recovered from a trailing vert (true =
130131
/// recovered).
131-
fn parse_pat_allow_top_alt_inner(
132+
fn parse_pat_no_top_guard_inner(
132133
&mut self,
133134
expected: Option<Expected>,
134135
rc: RecoverComma,
@@ -229,7 +230,7 @@ impl<'a> Parser<'a> {
229230
// We use `parse_pat_allow_top_alt` regardless of whether we actually want top-level
230231
// or-patterns so that we can detect when a user tries to use it. This allows us to print a
231232
// better error message.
232-
let (pat, trailing_vert) = self.parse_pat_allow_top_alt_inner(
233+
let (pat, trailing_vert) = self.parse_pat_no_top_guard_inner(
233234
expected,
234235
rc,
235236
RecoverColon::No,
@@ -696,7 +697,7 @@ impl<'a> Parser<'a> {
696697
} else if self.check(&token::OpenDelim(Delimiter::Bracket)) {
697698
// Parse `[pat, pat,...]` as a slice pattern.
698699
let (pats, _) = self.parse_delim_comma_seq(Delimiter::Bracket, |p| {
699-
p.parse_pat_allow_top_alt(
700+
p.parse_pat_no_top_guard(
700701
None,
701702
RecoverComma::No,
702703
RecoverColon::No,
@@ -944,7 +945,7 @@ impl<'a> Parser<'a> {
944945
let open_paren = self.token.span;
945946

946947
let (fields, trailing_comma) = self.parse_paren_comma_seq(|p| {
947-
p.parse_pat_allow_top_alt(
948+
p.parse_pat_no_top_guard(
948949
None,
949950
RecoverComma::No,
950951
RecoverColon::No,
@@ -1359,7 +1360,7 @@ impl<'a> Parser<'a> {
13591360
path: Path,
13601361
) -> PResult<'a, PatKind> {
13611362
let (fields, _) = self.parse_paren_comma_seq(|p| {
1362-
p.parse_pat_allow_top_alt(
1363+
p.parse_pat_no_top_guard(
13631364
None,
13641365
RecoverComma::No,
13651366
RecoverColon::No,
@@ -1394,7 +1395,7 @@ impl<'a> Parser<'a> {
13941395
self.parse_builtin(|self_, _lo, ident| {
13951396
Ok(match ident.name {
13961397
// builtin#deref(PAT)
1397-
sym::deref => Some(ast::PatKind::Deref(self_.parse_pat_allow_top_alt(
1398+
sym::deref => Some(ast::PatKind::Deref(self_.parse_pat_no_top_guard(
13981399
None,
13991400
RecoverComma::Yes,
14001401
RecoverColon::Yes,
@@ -1669,7 +1670,7 @@ impl<'a> Parser<'a> {
16691670
// Parsing a pattern of the form `fieldname: pat`.
16701671
let fieldname = self.parse_field_name()?;
16711672
self.bump();
1672-
let pat = self.parse_pat_allow_top_alt(
1673+
let pat = self.parse_pat_no_top_guard(
16731674
None,
16741675
RecoverComma::No,
16751676
RecoverColon::No,

compiler/rustc_parse/src/parser/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ impl<'a> Parser<'a> {
469469
PathStyle::Pat
470470
if let Ok(_) = self
471471
.parse_paren_comma_seq(|p| {
472-
p.parse_pat_allow_top_alt(
472+
p.parse_pat_no_top_guard(
473473
None,
474474
RecoverComma::No,
475475
RecoverColon::No,

0 commit comments

Comments
 (0)