Account for ADT bodies and struct expressions
This commit is contained in:
parent
375f025805
commit
38fd5a9acf
12 changed files with 142 additions and 2 deletions
|
@ -3039,6 +3039,7 @@ impl<'a> Parser<'a> {
|
|||
/// Parses `ident (COLON expr)?`.
|
||||
fn parse_expr_field(&mut self) -> PResult<'a, ExprField> {
|
||||
let attrs = self.parse_outer_attributes()?;
|
||||
self.recover_diff_marker();
|
||||
self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
|
||||
let lo = this.token.span;
|
||||
|
||||
|
|
|
@ -1385,7 +1385,9 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
fn parse_enum_variant(&mut self) -> PResult<'a, Option<Variant>> {
|
||||
self.recover_diff_marker();
|
||||
let variant_attrs = self.parse_outer_attributes()?;
|
||||
self.recover_diff_marker();
|
||||
self.collect_tokens_trailing_token(
|
||||
variant_attrs,
|
||||
ForceCollect::No,
|
||||
|
@ -1579,9 +1581,32 @@ impl<'a> Parser<'a> {
|
|||
self.parse_paren_comma_seq(|p| {
|
||||
let attrs = p.parse_outer_attributes()?;
|
||||
p.collect_tokens_trailing_token(attrs, ForceCollect::No, |p, attrs| {
|
||||
let mut snapshot = None;
|
||||
if p.is_diff_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt) {
|
||||
// Account for `<<<<<<<` diff markers. We can't proactivelly error here because
|
||||
// that can be a valid type start, so we snapshot and reparse only we've
|
||||
// encountered another parse error.
|
||||
snapshot = Some(p.create_snapshot_for_diagnostic());
|
||||
}
|
||||
let lo = p.token.span;
|
||||
let vis = p.parse_visibility(FollowedByType::Yes)?;
|
||||
let ty = p.parse_ty()?;
|
||||
let vis = match p.parse_visibility(FollowedByType::Yes) {
|
||||
Ok(vis) => vis,
|
||||
Err(err) => {
|
||||
if let Some(ref mut snapshot) = snapshot {
|
||||
snapshot.recover_diff_marker();
|
||||
}
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
let ty = match p.parse_ty() {
|
||||
Ok(ty) => ty,
|
||||
Err(err) => {
|
||||
if let Some(ref mut snapshot) = snapshot {
|
||||
snapshot.recover_diff_marker();
|
||||
}
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
|
||||
Ok((
|
||||
FieldDef {
|
||||
|
@ -1602,7 +1627,9 @@ impl<'a> Parser<'a> {
|
|||
|
||||
/// Parses an element of a struct declaration.
|
||||
fn parse_field_def(&mut self, adt_ty: &str) -> PResult<'a, FieldDef> {
|
||||
self.recover_diff_marker();
|
||||
let attrs = self.parse_outer_attributes()?;
|
||||
self.recover_diff_marker();
|
||||
self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
|
||||
let lo = this.token.span;
|
||||
let vis = this.parse_visibility(FollowedByType::No)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue