Rollup merge of #99786 - obeis:issue-99625, r=compiler-errors
Recover from C++ style `enum struct` Closes #99625
This commit is contained in:
commit
9c18fdc71f
4 changed files with 53 additions and 0 deletions
|
@ -1216,6 +1216,25 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
/// Parses an enum declaration.
|
/// Parses an enum declaration.
|
||||||
fn parse_item_enum(&mut self) -> PResult<'a, ItemInfo> {
|
fn parse_item_enum(&mut self) -> PResult<'a, ItemInfo> {
|
||||||
|
if self.token.is_keyword(kw::Struct) {
|
||||||
|
let mut err = self.struct_span_err(
|
||||||
|
self.prev_token.span.to(self.token.span),
|
||||||
|
"`enum` and `struct` are mutually exclusive",
|
||||||
|
);
|
||||||
|
err.span_suggestion(
|
||||||
|
self.prev_token.span.to(self.token.span),
|
||||||
|
"replace `enum struct` with",
|
||||||
|
"enum",
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
|
if self.look_ahead(1, |t| t.is_ident()) {
|
||||||
|
self.bump();
|
||||||
|
err.emit();
|
||||||
|
} else {
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let id = self.parse_ident()?;
|
let id = self.parse_ident()?;
|
||||||
let mut generics = self.parse_generics()?;
|
let mut generics = self.parse_generics()?;
|
||||||
generics.where_clause = self.parse_where_clause()?;
|
generics.where_clause = self.parse_where_clause()?;
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
pub enum Range {
|
||||||
|
//~^ ERROR `enum` and `struct` are mutually exclusive
|
||||||
|
Valid {
|
||||||
|
begin: u32,
|
||||||
|
len: u32,
|
||||||
|
},
|
||||||
|
Out,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
pub enum struct Range {
|
||||||
|
//~^ ERROR `enum` and `struct` are mutually exclusive
|
||||||
|
Valid {
|
||||||
|
begin: u32,
|
||||||
|
len: u32,
|
||||||
|
},
|
||||||
|
Out,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
error: `enum` and `struct` are mutually exclusive
|
||||||
|
--> $DIR/issue-99625-enum-struct-mutually-exclusive.rs:3:5
|
||||||
|
|
|
||||||
|
LL | pub enum struct Range {
|
||||||
|
| ^^^^^^^^^^^ help: replace `enum struct` with: `enum`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue