diagnostics: suggest naming a field after failing to parse
This commit is contained in:
parent
d496a4f8bb
commit
6713dde898
3 changed files with 27 additions and 5 deletions
|
@ -3037,6 +3037,19 @@ impl<'a> Parser<'a> {
|
||||||
",",
|
",",
|
||||||
Applicability::MachineApplicable,
|
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 {
|
if !recover {
|
||||||
|
|
|
@ -8,8 +8,9 @@ error: expected one of `,`, `:`, or `}`, found `.`
|
||||||
--> $DIR/issue-52496.rs:8:22
|
--> $DIR/issue-52496.rs:8:22
|
||||||
|
|
|
|
||||||
LL | let _ = Foo { bar.into(), bat: -1, . };
|
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
|
| while parsing this struct
|
||||||
|
|
||||||
error: expected identifier, found `.`
|
error: expected identifier, found `.`
|
||||||
|
|
|
@ -24,11 +24,19 @@ error: expected one of `,`, `:`, or `}`, found `{`
|
||||||
--> $DIR/issue-62973.rs:6:8
|
--> $DIR/issue-62973.rs:6:8
|
||||||
|
|
|
|
||||||
LL | fn p() { match s { v, E { [) {) }
|
LL | fn p() { match s { v, E { [) {) }
|
||||||
| ^ - -^ expected one of `,`, `:`, or `}`
|
| ^ - ^ expected one of `,`, `:`, or `}`
|
||||||
| | | |
|
| | |
|
||||||
| | | help: `}` may belong here
|
|
||||||
| | while parsing this struct
|
| | while parsing this struct
|
||||||
| unclosed delimiter
|
| 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
|
error: struct literals are not allowed here
|
||||||
--> $DIR/issue-62973.rs:6:16
|
--> $DIR/issue-62973.rs:6:16
|
||||||
|
|
Loading…
Add table
Reference in a new issue