diff options
| author | fee1-dead <ent3rm4n@gmail.com> | 2022-09-26 13:09:41 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-26 13:09:41 +0800 |
| commit | 0adf293f87fb354bf9a44e3e2f1c2b5a3578d880 (patch) | |
| tree | de6db736182f66faf40c4b7b90bca3695a56dd45 /compiler | |
| parent | 3288d3a305ad15cfcdcd9ef72404be6d2a2887b5 (diff) | |
| parent | c66c2e82c1a405ed3fff99953ab96de03806ca09 (diff) | |
| download | rust-0adf293f87fb354bf9a44e3e2f1c2b5a3578d880.tar.gz rust-0adf293f87fb354bf9a44e3e2f1c2b5a3578d880.zip | |
Rollup merge of #102143 - Rageking8:fix-101540, r=TaKO8Ki
Recover from struct nested in struct Fixes #101540 r? `@TaKO8Ki` Not sure If I have done it right.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index e55b5ce71cd..e385ac44113 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1715,6 +1715,7 @@ impl<'a> Parser<'a> { fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident> { let (ident, is_raw) = self.ident_or_err()?; if !is_raw && ident.is_reserved() { + let snapshot = self.create_snapshot_for_diagnostic(); let err = if self.check_fn_front_matter(false) { let inherited_vis = Visibility { span: rustc_span::DUMMY_SP, @@ -1735,6 +1736,22 @@ impl<'a> Parser<'a> { err.help("unlike in C++, Java, and C#, functions are declared in `impl` blocks"); err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information"); err + } else if self.eat_keyword(kw::Struct) { + match self.parse_item_struct() { + Ok((ident, _)) => { + let mut err = self.struct_span_err( + lo.with_hi(ident.span.hi()), + &format!("structs are not allowed in {adt_ty} definitions"), + ); + err.help("consider creating a new `struct` definition instead of nesting"); + err + } + Err(err) => { + err.cancel(); + self.restore_snapshot(snapshot); + self.expected_ident_found() + } + } } else { self.expected_ident_found() }; |
