Skip to content

Invalid Suggestion in "specify the associated type" help #155578

@asquared31415

Description

@asquared31415

Code

trait Meow {
    type Assoc;
}

struct Cat;

impl Meow for Cat {
    type Assoc = i32;
}

fn main() {
    let cat = Cat;
    let d: &dyn Meow<> = &cat;
}

Current output

error[E0191]: the value of the associated type `Assoc` in `Meow` must be specified
  --> src/main.rs:13:17
   |
 2 |     type Assoc;
   |     ---------- `Assoc` defined here
...
13 |     let d: &dyn Meow<> = &cat;
   |                 ^^^^^^
   |
help: specify the associated type
   |
13 |     let d: &dyn Meow<, Assoc = /* Type */> = &cat;
   |                      ++++++++++++++++++++

Desired output

help: specify the associated type
   |
13 |     let d: &dyn Meow<Assoc = /* Type */> = &cat;
   |                      ++++++++++++++++++

Rationale and extra context

When using an empty <> to specify no associated types (this is actually valid if there are no associated types), the compiler suggests adding a leading comma inside the <>, but this is invalid.

Rust Version

rustc 1.96.0-nightly (900485642 2026-04-08)
binary: rustc
commit-hash: 900485642855f4729d926ecf24680a791f9293cf
commit-date: 2026-04-08
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.2

@rustbot label +D-invalid-suggestion

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions