-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recover from struct nested in struct #101847
Conversation
r? @TaKO8Ki (rust-highfive has picked a reviewer for you, use r? to override) |
First time contributing to an open source project, please guide me step by step if there are any mistakes made in this PR. Thanks. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late response. I left some comments.
} else if self.check_keyword(kw::Struct) { | ||
let kw_token = self.token.clone(); | ||
let item = self.parse_item(ForceCollect::No)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use Parser::parse_item_struct
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation would eventually look something like the following:
// create a snapshot by using `Parser::ccreate_snapshot_for_diagnostic` at line 1707
// ..
} 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()
}
}
}
); | ||
err.span_suggestion( | ||
item.unwrap().span, | ||
&format!("consider creating a new `struct` definition instead of nesting"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you just use &str
?
&format!("consider creating a new `struct` definition instead of nesting"), | |
"consider creating a new `struct` definition instead of nesting", |
err.span_suggestion( | ||
item.unwrap().span, | ||
&format!("consider creating a new `struct` definition instead of nesting"), | ||
"", | ||
Applicability::MaybeIncorrect, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this suggestion should be like the following:
err.span_suggestion( | |
item.unwrap().span, | |
&format!("consider creating a new `struct` definition instead of nesting"), | |
"", | |
Applicability::MaybeIncorrect, | |
); | |
err.span_help("consider creating a new `struct` definition instead of nesting"); |
@rustbot author |
The recent miri to subtree thing kinda messed up my git stuff (I am new to git). Will do this in a separate PR. |
Fixes #101540