mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
diagnostics: suggest naming a field after failing to parse
This commit is contained in:
parent
d496a4f8bb
commit
6713dde898
@ -3037,6 +3037,19 @@ impl<'a> Parser<'a> {
|
||||
",",
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
} else if is_shorthand
|
||||
&& (AssocOp::from_token(&self.token).is_some()
|
||||
|| matches!(&self.token.kind, token::OpenDelim(_))
|
||||
|| self.token.kind == token::Dot)
|
||||
{
|
||||
// Looks like they tried to write a shorthand, complex expression.
|
||||
let ident = parsed_field.expect("is_shorthand implies Some").ident;
|
||||
e.span_suggestion(
|
||||
ident.span.shrink_to_lo(),
|
||||
"try naming a field",
|
||||
&format!("{ident}: "),
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
}
|
||||
}
|
||||
if !recover {
|
||||
|
@ -8,8 +8,9 @@ error: expected one of `,`, `:`, or `}`, found `.`
|
||||
--> $DIR/issue-52496.rs:8:22
|
||||
|
|
||||
LL | let _ = Foo { bar.into(), bat: -1, . };
|
||||
| --- ^ expected one of `,`, `:`, or `}`
|
||||
| |
|
||||
| --- - ^ expected one of `,`, `:`, or `}`
|
||||
| | |
|
||||
| | help: try naming a field: `bar:`
|
||||
| while parsing this struct
|
||||
|
||||
error: expected identifier, found `.`
|
||||
|
@ -24,11 +24,19 @@ error: expected one of `,`, `:`, or `}`, found `{`
|
||||
--> $DIR/issue-62973.rs:6:8
|
||||
|
|
||||
LL | fn p() { match s { v, E { [) {) }
|
||||
| ^ - -^ expected one of `,`, `:`, or `}`
|
||||
| | | |
|
||||
| | | help: `}` may belong here
|
||||
| ^ - ^ expected one of `,`, `:`, or `}`
|
||||
| | |
|
||||
| | while parsing this struct
|
||||
| unclosed delimiter
|
||||
|
|
||||
help: `}` may belong here
|
||||
|
|
||||
LL | fn p() { match s { v, E} { [) {) }
|
||||
| +
|
||||
help: try naming a field
|
||||
|
|
||||
LL | fn p() { match s { v, E: E { [) {) }
|
||||
| ++
|
||||
|
||||
error: struct literals are not allowed here
|
||||
--> $DIR/issue-62973.rs:6:16
|
||||
|
Loading…
Reference in New Issue
Block a user