Skip to content

Misleading suggestion to add bound to type alias parameter #125789

Closed
@johannesherschel

Description

@johannesherschel

Code

trait Trait {
    type Assoc;
}

type AssocOf<T> = T::Assoc;

Current output

error[E0220]: associated type `Assoc` not found for `T`
 --> lib.rs:5:22
  |
5 | type AssocOf<T> = T::Assoc;
  |                      ^^^^^ there is an associated type `Assoc` in the trait `Trait`
  |
help: consider restricting type parameter `T`
  |
5 | type AssocOf<T: Trait> = T::Assoc;
  |               +++++++

Desired output

suggestion to use type AssocOf<T> = <T as Trait>::Assoc;

Rationale and extra context

Restricting T as suggested causes a warning about the bound being ignored, including the correct suggestion to write <T as Trait>::Assoc. If I understand #112792 correctly, type alias bounds will be supported eventually, but right now the suggestion is misleading.

Other cases

No response

Rust Version

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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