Skip to content

impl 'a Trait in argument position emits multible wrong diagnostics #102598

@lukas-code

Description

@lukas-code

I tried this almost-correct code: Playground

fn foo<'a>(_: impl 'a Sized) {}

The current output is:

 Compiling playground v0.0.1 (/playground) error: expected one of `:`, `@`, or `|`, found `)` --> src/lib.rs:1:28 | 1 | fn foo<'a>(_: impl 'a Sized) {} | ^ 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 | 1 | fn foo<'a>(_: impl 'a Sized: TypeName) {} | ++++++++++ help: if this is a type, explicitly ignore the parameter name | 1 | fn foo<'a>(_: impl 'a _: Sized) {} | ++ error: expected one of `)`, `+`, or `,`, found `Sized` --> src/lib.rs:1:23 | 1 | fn foo<'a>(_: impl 'a Sized) {} | -^^^^^ expected one of `)`, `+`, or `,` | | | help: missing `,` error: at least one trait must be specified --> src/lib.rs:1:15 | 1 | fn foo<'a>(_: impl 'a Sized) {} | ^^^^^^^ error: could not compile `playground` due to 3 previous errors 

Ideally the output should look like:

 Compiling playground v0.0.1 (/playground) error: expected `+` between lifetime and trait --> src/lib.rs:1:22 | 1 | fn foo<'a>(_: impl 'a + Sized) {} | ^ | | | help: missing `+` | error: could not compile `playground` due to 1 previous errors 

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions