rust/compiler/rustc_parse/src/parser
Matthias Krüger 9cda9e0ab6
Rollup merge of #106712 - Ezrashaw:impl-ref-trait, r=estebank
make error emitted on `impl &Trait` nicer

Fixes #106694

Turned out to be simpler than I thought, also added UI test.

Before: ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9bda53271ef3a8886793cf427b8cea91))
```text
error: expected one of `:`, ``@`,` or `|`, found `)`
 --> src/main.rs:2:22
  |
2 | fn foo(_: impl &Trait) {}
  |                      ^ expected one of `:`, ``@`,` or `|`
  |
  = note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
help: if this is a parameter name, give it a type
  |
2 | fn foo(_: impl Trait: &TypeName) {}
  |                ~~~~~~~~~~~~~~~~
help: if this is a type, explicitly ignore the parameter name
  |
2 | fn foo(_: impl _: &Trait) {}
  |                ++

error: expected one of `!`, `(`, `)`, `,`, `?`, `for`, `~`, lifetime, or path, found `&`
 --> src/main.rs:2:16
  |
2 | fn foo(_: impl &Trait) {}
  |               -^ expected one of 9 possible tokens
  |               |
  |               help: missing `,`

error: expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, `~`, lifetime, or path, found `&`
 --> src/main.rs:3:11
  |
3 | fn bar<T: &Trait>(_: T) {}
  |           ^ expected one of 10 possible tokens
```

After:
```text
error: expected a trait, found type
 --> <anon>:2:16
  |
2 | fn foo(_: impl &Trait) {}
  |                -^^^^^
  |                |
  |                help: consider removing the indirection

error: expected a trait, found type
 --> <anon>:3:11
  |
3 | fn bar<T: &Trait>(_: T) {}
  |           -^^^^^
  |           |
  |           help: consider removing the indirection
```
2023-01-17 05:25:21 +01:00
..
attr_wrapper.rs compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
attr.rs compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
diagnostics.rs Detect struct literal needing parentheses 2023-01-11 16:53:21 +00:00
expr.rs Rollup merge of #106849 - WaffleLapkin:unvec, r=Nilstrieb 2023-01-14 18:45:28 +01:00
generics.rs parser: recover from where clauses placed before tuple struct bodies 2023-01-11 17:54:48 +01:00
item.rs Auto merge of #106537 - fmease:recover-where-clause-before-tuple-struct-body, r=estebank 2023-01-12 02:16:16 +00:00
mod.rs parse const closures 2023-01-12 02:28:37 +00:00
nonterminal.rs rustc_parse: remove ref patterns 2022-11-22 18:49:16 +00:00
pat.rs Fix some missed double spaces. 2023-01-14 18:23:40 +01:00
path.rs clippy::complexity fixes 2022-12-19 00:04:28 +01:00
stmt.rs Make LhsExpr::AlreadyParsed a named struct 2023-01-14 11:28:14 +00:00
ty.rs fix dropping diagnostic without emit 2023-01-16 16:18:56 +13:00