mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Account for ADT bodies and struct expressions
This commit is contained in:
parent
375f025805
commit
38fd5a9acf
@ -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)?;
|
||||
|
9
src/test/ui/parser/diff-markers/enum-2.rs
Normal file
9
src/test/ui/parser/diff-markers/enum-2.rs
Normal file
@ -0,0 +1,9 @@
|
||||
enum E {
|
||||
Foo {
|
||||
<<<<<<< HEAD //~ ERROR encountered diff marker
|
||||
x: u8,
|
||||
=======
|
||||
x: i8,
|
||||
>>>>>>> branch
|
||||
}
|
||||
}
|
14
src/test/ui/parser/diff-markers/enum-2.stderr
Normal file
14
src/test/ui/parser/diff-markers/enum-2.stderr
Normal 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
|
||||
|
7
src/test/ui/parser/diff-markers/enum.rs
Normal file
7
src/test/ui/parser/diff-markers/enum.rs
Normal file
@ -0,0 +1,7 @@
|
||||
enum E {
|
||||
<<<<<<< HEAD //~ ERROR encountered diff marker
|
||||
Foo(u8),
|
||||
=======
|
||||
Bar(i8),
|
||||
>>>>>>> branch
|
||||
}
|
14
src/test/ui/parser/diff-markers/enum.stderr
Normal file
14
src/test/ui/parser/diff-markers/enum.stderr
Normal 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
|
||||
|
12
src/test/ui/parser/diff-markers/struct-expr.rs
Normal file
12
src/test/ui/parser/diff-markers/struct-expr.rs
Normal file
@ -0,0 +1,12 @@
|
||||
struct S {
|
||||
x: u8,
|
||||
}
|
||||
fn main() {
|
||||
let _ = S {
|
||||
<<<<<<< HEAD //~ ERROR encountered diff marker
|
||||
x: 42,
|
||||
=======
|
||||
x: 0,
|
||||
>>>>>>> branch
|
||||
}
|
||||
}
|
14
src/test/ui/parser/diff-markers/struct-expr.stderr
Normal file
14
src/test/ui/parser/diff-markers/struct-expr.stderr
Normal 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
|
||||
|
7
src/test/ui/parser/diff-markers/struct.rs
Normal file
7
src/test/ui/parser/diff-markers/struct.rs
Normal file
@ -0,0 +1,7 @@
|
||||
struct S {
|
||||
<<<<<<< HEAD //~ ERROR encountered diff marker
|
||||
x: u8,
|
||||
=======
|
||||
x: i8,
|
||||
>>>>>>> branch
|
||||
}
|
14
src/test/ui/parser/diff-markers/struct.stderr
Normal file
14
src/test/ui/parser/diff-markers/struct.stderr
Normal 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
|
||||
|
7
src/test/ui/parser/diff-markers/tuple-struct.rs
Normal file
7
src/test/ui/parser/diff-markers/tuple-struct.rs
Normal file
@ -0,0 +1,7 @@
|
||||
struct S(
|
||||
<<<<<<< HEAD //~ ERROR encountered diff marker
|
||||
u8,
|
||||
=======
|
||||
i8,
|
||||
>>>>>>> branch
|
||||
);
|
14
src/test/ui/parser/diff-markers/tuple-struct.stderr
Normal file
14
src/test/ui/parser/diff-markers/tuple-struct.stderr
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user