Skip to content

Commit b2966e6

Browse files
committed
parser: bool -> GateOr.
1 parent b205055 commit b2966e6

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/libsyntax/parse/parser/expr.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::{Parser, PResult, Restrictions, PrevTokenKind, TokenType, PathStyle};
22
use super::{BlockMode, SemiColonMode};
33
use super::{SeqSep, TokenExpectType};
4+
use super::pat::GateOr;
45

56
use crate::maybe_recover_from_interpolated_ty_qpath;
67
use crate::ptr::P;
@@ -1246,7 +1247,7 @@ impl<'a> Parser<'a> {
12461247
fn parse_let_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
12471248
let lo = self.prev_span;
12481249
// FIXME(or_patterns, Centril | dlrobertson): use `parse_top_pat` instead.
1249-
let pat = self.parse_top_pat_unpack(false)?;
1250+
let pat = self.parse_top_pat_unpack(GateOr::No)?;
12501251
self.expect(&token::Eq)?;
12511252
let expr = self.with_res(
12521253
Restrictions::NO_STRUCT_LITERAL,
@@ -1284,7 +1285,7 @@ impl<'a> Parser<'a> {
12841285
_ => None,
12851286
};
12861287

1287-
let pat = self.parse_top_pat(true)?;
1288+
let pat = self.parse_top_pat(GateOr::Yes)?;
12881289
if !self.eat_keyword(kw::In) {
12891290
let in_span = self.prev_span.between(self.token.span);
12901291
self.struct_span_err(in_span, "missing `in` in `for` loop")
@@ -1389,7 +1390,7 @@ impl<'a> Parser<'a> {
13891390
let attrs = self.parse_outer_attributes()?;
13901391
let lo = self.token.span;
13911392
// FIXME(or_patterns, Centril | dlrobertson): use `parse_top_pat` instead.
1392-
let pat = self.parse_top_pat_unpack(false)?;
1393+
let pat = self.parse_top_pat_unpack(GateOr::No)?;
13931394
let guard = if self.eat_keyword(kw::If) {
13941395
Some(self.parse_expr()?)
13951396
} else {

src/libsyntax/parse/parser/pat.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ use errors::{Applicability, DiagnosticBuilder};
1414

1515
type Expected = Option<&'static str>;
1616

17+
/// Whether or not an or-pattern should be gated when occurring in the current context.
18+
#[derive(PartialEq)]
19+
pub enum GateOr { Yes, No }
20+
1721
impl<'a> Parser<'a> {
1822
/// Parses a pattern.
1923
///
@@ -26,7 +30,7 @@ impl<'a> Parser<'a> {
2630

2731
// FIXME(or_patterns, Centril | dlrobertson):
2832
// remove this and use `parse_top_pat` everywhere it is used instead.
29-
pub(super) fn parse_top_pat_unpack(&mut self, gate_or: bool) -> PResult<'a, Vec<P<Pat>>> {
33+
pub(super) fn parse_top_pat_unpack(&mut self, gate_or: GateOr) -> PResult<'a, Vec<P<Pat>>> {
3034
self.parse_top_pat(gate_or)
3135
.map(|pat| pat.and_then(|pat| match pat.node {
3236
PatKind::Or(pats) => pats,
@@ -36,9 +40,9 @@ impl<'a> Parser<'a> {
3640

3741
/// Entry point to the main pattern parser.
3842
/// Corresponds to `top_pat` in RFC 2535 and allows or-pattern at the top level.
39-
pub(super) fn parse_top_pat(&mut self, gate_or: bool) -> PResult<'a, P<Pat>> {
43+
pub(super) fn parse_top_pat(&mut self, gate_or: GateOr) -> PResult<'a, P<Pat>> {
4044
// Allow a '|' before the pats (RFCs 1925, 2530, and 2535).
41-
if self.eat_or_separator() && gate_or {
45+
if self.eat_or_separator() && gate_or == GateOr::Yes {
4246
self.sess.gated_spans.or_patterns.borrow_mut().push(self.prev_span);
4347
}
4448

@@ -50,7 +54,7 @@ impl<'a> Parser<'a> {
5054
fn parse_pat_with_or(
5155
&mut self,
5256
expected: Expected,
53-
gate_or: bool,
57+
gate_or: GateOr,
5458
top_level: bool
5559
) -> PResult<'a, P<Pat>> {
5660
// Parse the first pattern.
@@ -73,7 +77,7 @@ impl<'a> Parser<'a> {
7377
let or_pattern_span = lo.to(self.prev_span);
7478

7579
// Feature gate the or-pattern if instructed:
76-
if gate_or {
80+
if gate_or == GateOr::Yes {
7781
self.sess.gated_spans.or_patterns.borrow_mut().push(or_pattern_span);
7882
}
7983

@@ -171,7 +175,7 @@ impl<'a> Parser<'a> {
171175
self.bump();
172176
}
173177

174-
self.parse_pat_with_or(expected, true, false)
178+
self.parse_pat_with_or(expected, GateOr::Yes, false)
175179
}
176180

177181
/// Parses a pattern, with a setting whether modern range patterns (e.g., `a..=b`, `a..b` are

src/libsyntax/parse/parser/stmt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::{Parser, PResult, Restrictions, PrevTokenKind, SemiColonMode, BlockMode};
22
use super::expr::LhsExpr;
33
use super::path::PathStyle;
4+
use super::pat::GateOr;
45

56
use crate::ptr::P;
67
use crate::{maybe_whole, ThinVec};
@@ -207,7 +208,7 @@ impl<'a> Parser<'a> {
207208
/// Parses a local variable declaration.
208209
fn parse_local(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Local>> {
209210
let lo = self.prev_span;
210-
let pat = self.parse_top_pat(true)?;
211+
let pat = self.parse_top_pat(GateOr::Yes)?;
211212

212213
let (err, ty) = if self.eat(&token::Colon) {
213214
// Save the state of the parser before parsing type normally, in case there is a `:`

0 commit comments

Comments
 (0)