Skip to content

Bare type in impl parameter list causes non-intuitive parse error #147889

@estebank

Description

@estebank

Code

impl<TkCanvas<Inst>> Deref for ChartDisplay<Inst> { // Note the incorrect `<TkCanvas<Inst>>` type Target = TkCanvas<Inst>; fn deref(&self) -> &Self::Target { &self.hull } }

Current output

error: expected `::`, found `Deref` --> src/lib.rs:6:22 | 6 | impl<TkCanvas<Inst>> Deref for ChartDisplay<Inst> { | ^^^^^ expected `::`

Desired output

error: expected type parameter, found path `TkCanvas<Inst>` --> src/lib.rs:6:22 | 6 | impl<TkCanvas<Inst>> Deref for ChartDisplay<Inst> { | ^^^^^^^^^^^^^^ expected type parameter, found path | help: you might have meant to bind a type parameter to a trait | 6 | impl<T: TkCanvas<Inst>> Deref for ChartDisplay<Inst> { | ++ help: alternatively, you might have meant to introduce type parameter | 6 | impl<Inst> Deref for ChartDisplay<Inst> { | ++++

Rationale and extra context

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=0f2e1d057720a06ecd77956f5b411416

Found in the wild at https://users.rust-lang.org/t/help-me-understand-this-compiler-error/134753

Other cases

Rust Version

1.90.0

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTP-lowLow priorityT-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