Skip to content

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

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

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    A-parserArea: The lexing & parsing of Rust source code to an AST
    P-lowLow priority
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 19, 2025
  2. maplethecolor commented on Oct 19, 2025

    @maplethecolor

    @rustbot claim

    I think the desired output given is mostly OK
    The second hint should suggest Inst: TkCanvas instead IMO, but that can be changed later on :)

  3. maplethecolor commented on Oct 19, 2025

    @maplethecolor

    Should this be extended to functions where such a mistake might happen too?
    Playground

    fn meow<Box<String>>() {}
  4. maplethecolor commented on Nov 29, 2025

    @maplethecolor

    Sorry; I haven't found the time to work on Rust due to life. Releasing.
    @rustbot release-assignment

  5. bb1yd commented on Jun 2, 2026

    @bb1yd
    Contributor

    @rustbot claim

  6. added 2 commits that reference this issue on Jul 6, 2026
    112062c
    baf02d2
  7. added a commit that references this issue on Jul 6, 2026
    aed2da5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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