let
is not allowed in struct field definitions
Co-authored-by: jyn514 <jyn514@gmail.com> Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
This commit is contained in:
parent
ab37a83ae2
commit
6071b4b8a6
@ -1788,7 +1788,23 @@ fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.expected_ident_found()
|
||||
let mut err = self.expected_ident_found();
|
||||
if let Some((ident, _)) = self.token.ident() && ident.as_str() == "let" {
|
||||
self.bump(); // `let`
|
||||
let span = self.prev_token.span.until(self.token.span);
|
||||
err.span_suggestion(
|
||||
span,
|
||||
"remove the let, the `let` keyword is not allowed in struct field definitions",
|
||||
String::new(),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
err.note("the `let` keyword is not allowed in `struct` fields");
|
||||
err.note("see <https://doc.rust-lang.org/book/ch05-01-defining-structs.html> for more information");
|
||||
err.emit();
|
||||
self.bump();
|
||||
return Ok(ident);
|
||||
}
|
||||
err
|
||||
};
|
||||
return Err(err);
|
||||
}
|
||||
|
@ -1,10 +1,16 @@
|
||||
error: expected identifier, found keyword `let`
|
||||
--> $DIR/removed-syntax-field-let.rs:2:5
|
||||
|
|
||||
LL | struct S {
|
||||
| - while parsing this struct
|
||||
LL | let foo: (),
|
||||
| ^^^ expected identifier, found keyword
|
||||
|
|
||||
= note: the `let` keyword is not allowed in `struct` fields
|
||||
= note: see <https://doc.rust-lang.org/book/ch05-01-defining-structs.html> for more information
|
||||
help: remove the let, the `let` keyword is not allowed in struct field definitions
|
||||
|
|
||||
LL - let foo: (),
|
||||
LL + foo: (),
|
||||
|
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user