Skip to content

Commit acb1130

Browse files
committed
parser: TopLevel -> RecoverComma.
1 parent 6a73199 commit acb1130

File tree

1 file changed

+10
-10
lines changed
  • src/libsyntax/parse/parser

1 file changed

+10
-10
lines changed

src/libsyntax/parse/parser/pat.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ pub(super) const PARAM_EXPECTED: Expected = Some("parameter name");
2121
#[derive(PartialEq)]
2222
pub enum GateOr { Yes, No }
2323

24-
/// Whether or not this is the top level pattern context.
24+
/// Whether or not to recover a `,` when parsing or-patterns.
2525
#[derive(PartialEq, Copy, Clone)]
26-
enum TopLevel { Yes, No }
26+
enum RecoverComma { Yes, No }
2727

2828
impl<'a> Parser<'a> {
2929
/// Parses a pattern.
@@ -52,7 +52,7 @@ impl<'a> Parser<'a> {
5252
let gated_leading_vert = self.eat_or_separator() && gate_or == GateOr::Yes;
5353

5454
// Parse the possibly-or-pattern.
55-
let pat = self.parse_pat_with_or(None, gate_or, TopLevel::Yes)?;
55+
let pat = self.parse_pat_with_or(None, gate_or, RecoverComma::Yes)?;
5656

5757
// If we parsed a leading `|` which should be gated,
5858
// and no other gated or-pattern has been parsed thus far,
@@ -72,7 +72,7 @@ impl<'a> Parser<'a> {
7272
/// Special recovery is provided for or-patterns and leading `|`.
7373
pub(super) fn parse_fn_param_pat(&mut self) -> PResult<'a, P<Pat>> {
7474
self.recover_leading_vert("not allowed in a parameter pattern");
75-
let pat = self.parse_pat_with_or(PARAM_EXPECTED, GateOr::No, TopLevel::No)?;
75+
let pat = self.parse_pat_with_or(PARAM_EXPECTED, GateOr::No, RecoverComma::No)?;
7676

7777
if let PatKind::Or(..) = &pat.node {
7878
self.ban_illegal_fn_param_or_pat(&pat);
@@ -96,11 +96,11 @@ impl<'a> Parser<'a> {
9696
&mut self,
9797
expected: Expected,
9898
gate_or: GateOr,
99-
top_level: TopLevel,
99+
rc: RecoverComma,
100100
) -> PResult<'a, P<Pat>> {
101101
// Parse the first pattern.
102102
let first_pat = self.parse_pat(expected)?;
103-
self.maybe_recover_unexpected_comma(first_pat.span, top_level)?;
103+
self.maybe_recover_unexpected_comma(first_pat.span, rc)?;
104104

105105
// If the next token is not a `|`,
106106
// this is not an or-pattern and we should exit here.
@@ -115,7 +115,7 @@ impl<'a> Parser<'a> {
115115
err.span_label(lo, "while parsing this or-pattern staring here");
116116
err
117117
})?;
118-
self.maybe_recover_unexpected_comma(pat.span, top_level)?;
118+
self.maybe_recover_unexpected_comma(pat.span, rc)?;
119119
pats.push(pat);
120120
}
121121
let or_pattern_span = lo.to(self.prev_span);
@@ -156,8 +156,8 @@ impl<'a> Parser<'a> {
156156

157157
/// Some special error handling for the "top-level" patterns in a match arm,
158158
/// `for` loop, `let`, &c. (in contrast to subpatterns within such).
159-
fn maybe_recover_unexpected_comma(&mut self, lo: Span, top_level: TopLevel) -> PResult<'a, ()> {
160-
if top_level == TopLevel::No || self.token != token::Comma {
159+
fn maybe_recover_unexpected_comma(&mut self, lo: Span, rc: RecoverComma) -> PResult<'a, ()> {
160+
if rc == RecoverComma::No || self.token != token::Comma {
161161
return Ok(());
162162
}
163163

@@ -207,7 +207,7 @@ impl<'a> Parser<'a> {
207207
/// See `parse_pat_with_or` for details on parsing or-patterns.
208208
fn parse_pat_with_or_inner(&mut self) -> PResult<'a, P<Pat>> {
209209
self.recover_leading_vert("only allowed in a top-level pattern");
210-
self.parse_pat_with_or(None, GateOr::Yes, TopLevel::No)
210+
self.parse_pat_with_or(None, GateOr::Yes, RecoverComma::No)
211211
}
212212

213213
/// Recover if `|` or `||` is here.

0 commit comments

Comments
 (0)