diff options
| author | León Orell Valerian Liehr <liehr.exchange@gmx.net> | 2023-01-06 17:47:21 +0100 |
|---|---|---|
| committer | León Orell Valerian Liehr <liehr.exchange@gmx.net> | 2023-01-11 17:54:48 +0100 |
| commit | 70ddde76dfbb03909c565b329f86e49de1f767cc (patch) | |
| tree | 70f3b7a49c33c052749413d30547e52dd913a7b2 /compiler/rustc_parse/src/parser/item.rs | |
| parent | b22c152958eade17a71d899b29a2d39bcc77aa48 (diff) | |
| download | rust-70ddde76dfbb03909c565b329f86e49de1f767cc.tar.gz rust-70ddde76dfbb03909c565b329f86e49de1f767cc.zip | |
parser: recover from where clauses placed before tuple struct bodies
Diffstat (limited to 'compiler/rustc_parse/src/parser/item.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index a958c294930..5c6650acd8a 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1454,8 +1454,16 @@ impl<'a> Parser<'a> { // struct. let vdata = if self.token.is_keyword(kw::Where) { - generics.where_clause = self.parse_where_clause()?; - if self.eat(&token::Semi) { + let tuple_struct_body; + (generics.where_clause, tuple_struct_body) = + self.parse_struct_where_clause(class_name, generics.span)?; + + if let Some(body) = tuple_struct_body { + // If we see a misplaced tuple struct body: `struct Foo<T> where T: Copy, (T);` + let body = VariantData::Tuple(body, DUMMY_NODE_ID); + self.expect_semi()?; + body + } else if self.eat(&token::Semi) { // If we see a: `struct Foo<T> where T: Copy;` style decl. VariantData::Unit(DUMMY_NODE_ID) } else { @@ -1575,7 +1583,7 @@ impl<'a> Parser<'a> { Ok((fields, recovered)) } - fn parse_tuple_struct_body(&mut self) -> PResult<'a, Vec<FieldDef>> { + pub(super) fn parse_tuple_struct_body(&mut self) -> PResult<'a, Vec<FieldDef>> { // This is the case where we find `struct Foo<T>(T) where T: Copy;` // Unit like structs are handled in parse_item_struct function self.parse_paren_comma_seq(|p| { |
