Suggest struct pat on incorrect unit or tuple pat

When encountering a unit or tuple pattern for a struct-like item, suggest
using the correct pattern.

Use `insert_field_names_local` when evaluating variants and store field
names even when the list is empty in order to produce accurate
structured suggestions.
This commit is contained in:
Esteban Küber 2020-07-09 17:42:07 -07:00
parent 346aec9b02
commit 04298204ed
23 changed files with 236 additions and 136 deletions

View file

@ -33,13 +33,16 @@ LL | struct Foo { a: bool };
| ---------------------- `Foo` defined here
LL |
LL | let f = Foo();
| ^^^^^
|
help: a function with a similar name exists
|
LL | let f = foo();
| ^^^
| |
| did you mean `Foo { /* fields */ }`?
| help: a function with a similar name exists (notice the capitalization): `foo`
...
LL | fn foo() {
| -------- similarly named function `foo` defined here
help: use struct literal syntax instead
|
LL | let f = Foo { a: val };
| ^^^^^^^^^^^^^^
error[E0423]: expected value, found struct `T`
--> $DIR/E0423.rs:14:8