Skip to content

Commit

Permalink
Rollup merge of rust-lang#67148 - Centril:ty-polish, r=estebank
Browse files Browse the repository at this point in the history
 Refactor type & bounds parsing thoroughly

PR is based on rust-lang#67131 with first one from this PR being ` extract parse_ty_tuple_or_parens`.

Also fixes rust-lang#67146.

r? @estebank
  • Loading branch information
Centril committed Dec 22, 2019
2 parents 5535c25 + db4818f commit 616373e
Show file tree
Hide file tree
Showing 11 changed files with 371 additions and 286 deletions.
11 changes: 6 additions & 5 deletions src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ impl<'a> Parser<'a> {
self.parse_expr_res(Restrictions::empty(), None)
}

pub(super) fn parse_anon_const_expr(&mut self) -> PResult<'a, AnonConst> {
self.parse_expr().map(|value| AnonConst { id: DUMMY_NODE_ID, value })
}

fn parse_expr_catch_underscore(&mut self) -> PResult<'a, P<Expr>> {
match self.parse_expr() {
Ok(expr) => Ok(expr),
Expand All @@ -109,7 +113,7 @@ impl<'a> Parser<'a> {
}
}

/// Parses a sequence of expressions bounded by parentheses.
/// Parses a sequence of expressions delimited by parentheses.
fn parse_paren_expr_seq(&mut self) -> PResult<'a, Vec<P<Expr>>> {
self.parse_paren_comma_seq(|p| {
p.parse_expr_catch_underscore()
Expand Down Expand Up @@ -955,10 +959,7 @@ impl<'a> Parser<'a> {
let first_expr = self.parse_expr()?;
if self.eat(&token::Semi) {
// Repeating array syntax: `[ 0; 512 ]`
let count = AnonConst {
id: DUMMY_NODE_ID,
value: self.parse_expr()?,
};
let count = self.parse_anon_const_expr()?;
self.expect(close)?;
ExprKind::Repeat(first_expr, count)
} else if self.eat(&token::Comma) {
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::maybe_whole;

use rustc_errors::{PResult, Applicability, DiagnosticBuilder, StashKey};
use rustc_error_codes::*;
use syntax::ast::{self, DUMMY_NODE_ID, Ident, AttrVec, Attribute, AttrKind, AttrStyle, AnonConst};
use syntax::ast::{self, DUMMY_NODE_ID, Ident, AttrVec, Attribute, AttrKind, AttrStyle};
use syntax::ast::{AssocItem, AssocItemKind, Item, ItemKind, UseTree, UseTreeKind};
use syntax::ast::{PathSegment, IsAuto, Constness, IsAsync, Unsafety, Defaultness, Extern, StrLit};
use syntax::ast::{Visibility, VisibilityKind, Mutability, FnHeader, ForeignItem, ForeignItemKind};
Expand Down Expand Up @@ -1317,10 +1317,7 @@ impl<'a> Parser<'a> {
};

let disr_expr = if self.eat(&token::Eq) {
Some(AnonConst {
id: DUMMY_NODE_ID,
value: self.parse_expr()?,
})
Some(self.parse_anon_const_expr()?)
} else {
None
};
Expand Down
Loading

0 comments on commit 616373e

Please sign in to comment.