3842117ef2
Recover keywords in trait bounds (_this pr was inspired by [this tweet](https://twitter.com/Azumanga/status/1552982326409367561)_) Recover keywords in trait bound, motivational example: ```rust fn f(_: impl fn()) {} // mistyped, meant `Fn` ``` <details><summary>Current nightly (3 needless and confusing errors!)</summary> <p> ```text error: expected identifier, found keyword `fn` --> ./t.rs:1:15 | 1 | fn _f(_: impl fn()) {} | ^^ expected identifier, found keyword | help: escape `fn` to use it as an identifier | 1 | fn _f(_: impl r#fn()) {} | ++ error: expected one of `:` or `|`, found `)` --> ./t.rs:1:19 | 1 | fn _f(_: impl fn()) {} | ^ expected one of `:` or `|` error: expected one of `!`, `(`, `)`, `,`, `?`, `for`, `~`, lifetime, or path, found keyword `fn` --> ./t.rs:1:15 | 1 | fn _f(_: impl fn()) {} | -^^ expected one of 9 possible tokens | | | help: missing `,` error: at least one trait must be specified --> ./t.rs:1:10 | 1 | fn _f(_: impl fn()) {} | ^^^^ ``` </p> </details> This PR: ```text error: expected identifier, found keyword `fn` --> ./t.rs:1:15 | 1 | fn _f(_: impl fn()) {} | ^^ expected identifier, found keyword | help: escape `fn` to use it as an identifier | 1 | fn _f(_: impl r#fn()) {} | ++ error[E0405]: cannot find trait `r#fn` in this scope --> ./t.rs:1:15 | 1 | fn _f(_: impl fn()) {} | ^^ help: a trait with a similar name exists (notice the capitalization): `Fn` | ::: /home/waffle/projects/repos/rust/library/core/src/ops/function.rs:74:1 | 74 | pub trait Fn<Args>: FnMut<Args> { | ------------------------------- similarly named trait `Fn` defined here ``` It would be nice to have suggestion in the first error like "have you meant `Fn` trait", instead of a separate error, but the recovery is deep inside ident parsing, which makes it a lot harder to do. r? `@compiler-errors` |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |