Account for ADT bodies and struct expressions

This commit is contained in:
Esteban Küber 2022-12-28 18:26:59 -08:00
parent 375f025805
commit 38fd5a9acf
12 changed files with 142 additions and 2 deletions

View File

@ -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;

View File

@ -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)?;

View File

@ -0,0 +1,9 @@
enum E {
Foo {
<<<<<<< HEAD //~ ERROR encountered diff marker
x: u8,
=======
x: i8,
>>>>>>> branch
}
}

View File

@ -0,0 +1,14 @@
error: encountered diff marker
--> $DIR/enum-2.rs:3:1
|
LL | <<<<<<< HEAD
| ^^^^^^^ start
LL | x: u8,
LL | =======
| ^^^^^^^ middle
LL | x: i8,
LL | >>>>>>> branch
| ^^^^^^^ end
error: aborting due to previous error

View File

@ -0,0 +1,7 @@
enum E {
<<<<<<< HEAD //~ ERROR encountered diff marker
Foo(u8),
=======
Bar(i8),
>>>>>>> branch
}

View File

@ -0,0 +1,14 @@
error: encountered diff marker
--> $DIR/enum.rs:2:1
|
LL | <<<<<<< HEAD
| ^^^^^^^ start
LL | Foo(u8),
LL | =======
| ^^^^^^^ middle
LL | Bar(i8),
LL | >>>>>>> branch
| ^^^^^^^ end
error: aborting due to previous error

View File

@ -0,0 +1,12 @@
struct S {
x: u8,
}
fn main() {
let _ = S {
<<<<<<< HEAD //~ ERROR encountered diff marker
x: 42,
=======
x: 0,
>>>>>>> branch
}
}

View File

@ -0,0 +1,14 @@
error: encountered diff marker
--> $DIR/struct-expr.rs:6:1
|
LL | <<<<<<< HEAD
| ^^^^^^^ start
LL | x: 42,
LL | =======
| ^^^^^^^ middle
LL | x: 0,
LL | >>>>>>> branch
| ^^^^^^^ end
error: aborting due to previous error

View File

@ -0,0 +1,7 @@
struct S {
<<<<<<< HEAD //~ ERROR encountered diff marker
x: u8,
=======
x: i8,
>>>>>>> branch
}

View File

@ -0,0 +1,14 @@
error: encountered diff marker
--> $DIR/struct.rs:2:1
|
LL | <<<<<<< HEAD
| ^^^^^^^ start
LL | x: u8,
LL | =======
| ^^^^^^^ middle
LL | x: i8,
LL | >>>>>>> branch
| ^^^^^^^ end
error: aborting due to previous error

View File

@ -0,0 +1,7 @@
struct S(
<<<<<<< HEAD //~ ERROR encountered diff marker
u8,
=======
i8,
>>>>>>> branch
);

View File

@ -0,0 +1,14 @@
error: encountered diff marker
--> $DIR/tuple-struct.rs:2:1
|
LL | <<<<<<< HEAD
| ^^^^^^^ start
LL | u8,
LL | =======
| ^^^^^^^ middle
LL | i8,
LL | >>>>>>> branch
| ^^^^^^^ end
error: aborting due to previous error