syntax: improve parameter without type suggestions

This commit improves the suggestions provided when function parameters
do not have types:

- A new suggestion is added for arbitrary self types, which suggests
adding `self: ` before the type.

- Existing suggestions are now provided when a `<` is found where a `:`
was expected (previously only `,` and `)` or trait items), this gives
suggestions in the case where the unnamed parameter type is generic
in a free function.

- The suggestion that a type name be provided (e.g. `fn foo(HashMap<u32>)`
-> `fn foo(HashMap: TypeName<u32>)`) will no longer occur when a `<` was
found instead of `:`.

- The ident will not be used for recovery when a `<` was found instead
of `:`.

Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
David Wood
2019-10-01 15:17:50 +01:00
parent ff191b54cc
commit 2537a8aa7a
8 changed files with 93 additions and 8 deletions

View File

@@ -3,6 +3,12 @@ error: expected one of `:`, `@`, or `|`, found `<`
|
LL | fn a(B<) {}
| ^ expected one of `:`, `@`, or `|` here
|
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
help: if this is a type, explicitly ignore the parameter name
|
LL | fn a(_: B<) {}
| ^^^^
error: aborting due to previous error