mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 04:08:40 +00:00
recover from struct nested in struct
This commit is contained in:
parent
8ab71ab59f
commit
a1062b9bdc
@ -1715,6 +1715,7 @@ impl<'a> Parser<'a> {
|
|||||||
fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident> {
|
fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident> {
|
||||||
let (ident, is_raw) = self.ident_or_err()?;
|
let (ident, is_raw) = self.ident_or_err()?;
|
||||||
if !is_raw && ident.is_reserved() {
|
if !is_raw && ident.is_reserved() {
|
||||||
|
let snapshot = self.create_snapshot_for_diagnostic();
|
||||||
let err = if self.check_fn_front_matter(false) {
|
let err = if self.check_fn_front_matter(false) {
|
||||||
let inherited_vis = Visibility {
|
let inherited_vis = Visibility {
|
||||||
span: rustc_span::DUMMY_SP,
|
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("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.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information");
|
||||||
err
|
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 {
|
} else {
|
||||||
self.expected_ident_found()
|
self.expected_ident_found()
|
||||||
};
|
};
|
||||||
|
7
src/test/ui/parser/issues/issue-101540.rs
Normal file
7
src/test/ui/parser/issues/issue-101540.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
struct S1 {
|
||||||
|
struct S2 {
|
||||||
|
//~^ ERROR structs are not allowed in struct definitions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
10
src/test/ui/parser/issues/issue-101540.stderr
Normal file
10
src/test/ui/parser/issues/issue-101540.stderr
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
error: structs are not allowed in struct definitions
|
||||||
|
--> $DIR/issue-101540.rs:2:5
|
||||||
|
|
|
||||||
|
LL | struct S2 {
|
||||||
|
| _____-^^^^^
|
||||||
|
LL | |
|
||||||
|
LL | | }
|
||||||
|
| |_____- help: consider creating a new `struct` definition instead of nesting
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
Loading…
Reference in New Issue
Block a user