Misleading suggestion to add bound to type alias parameter · Issue #125789 · rust-lang/rust (original) (raw)
Code
trait Trait { type Assoc; }
type AssocOf = T::Assoc;
Current output
error[E0220]: associated type Assoc
not found for T
--> lib.rs:5:22
|
5 | type AssocOf = 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 = ::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