Skip to content

Commit af9901f

Browse files
authored
Rollup merge of rust-lang#67148 - Centril:ty-polish, r=estebank
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
2 parents 5535c25 + db4818f commit af9901f

11 files changed

+371
-286
lines changed

src/librustc_parse/parser/expr.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ impl<'a> Parser<'a> {
9090
self.parse_expr_res(Restrictions::empty(), None)
9191
}
9292

93+
pub(super) fn parse_anon_const_expr(&mut self) -> PResult<'a, AnonConst> {
94+
self.parse_expr().map(|value| AnonConst { id: DUMMY_NODE_ID, value })
95+
}
96+
9397
fn parse_expr_catch_underscore(&mut self) -> PResult<'a, P<Expr>> {
9498
match self.parse_expr() {
9599
Ok(expr) => Ok(expr),
@@ -109,7 +113,7 @@ impl<'a> Parser<'a> {
109113
}
110114
}
111115

112-
/// Parses a sequence of expressions bounded by parentheses.
116+
/// Parses a sequence of expressions delimited by parentheses.
113117
fn parse_paren_expr_seq(&mut self) -> PResult<'a, Vec<P<Expr>>> {
114118
self.parse_paren_comma_seq(|p| {
115119
p.parse_expr_catch_underscore()
@@ -955,10 +959,7 @@ impl<'a> Parser<'a> {
955959
let first_expr = self.parse_expr()?;
956960
if self.eat(&token::Semi) {
957961
// Repeating array syntax: `[ 0; 512 ]`
958-
let count = AnonConst {
959-
id: DUMMY_NODE_ID,
960-
value: self.parse_expr()?,
961-
};
962+
let count = self.parse_anon_const_expr()?;
962963
self.expect(close)?;
963964
ExprKind::Repeat(first_expr, count)
964965
} else if self.eat(&token::Comma) {

src/librustc_parse/parser/item.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::maybe_whole;
55

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

13191319
let disr_expr = if self.eat(&token::Eq) {
1320-
Some(AnonConst {
1321-
id: DUMMY_NODE_ID,
1322-
value: self.parse_expr()?,
1323-
})
1320+
Some(self.parse_anon_const_expr()?)
13241321
} else {
13251322
None
13261323
};

0 commit comments

Comments
 (0)