- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code:
playground
trait Foo {
    type Assoc;
}
impl Foo for () {
    type Assoc = ();
}
// trait w/ same name as the associated type in scope
trait Assoc {
    
}
// likely meant to use T::Assoc to get the associated type, not just one `:`
fn foo<T: Foo>(_x: T) -> Option<T:Assoc> {
    todo!()
}The current output is:
   Compiling playground v0.0.1 (/playground)
error[E0658]: associated type bounds are unstable
  --> src/lib.rs:15:33
   |
15 | fn foo<T: Foo>(_x: T) -> Option<T:Assoc> {
   |                                 ^^^^^^^
   |
   = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information
error[E0107]: this enum takes 1 generic argument but 0 generic arguments were supplied
   --> src/lib.rs:15:26
    |
15  | fn foo<T: Foo>(_x: T) -> Option<T:Assoc> {
    |                          ^^^^^^ expected 1 generic argument
    |
note: enum defined here, with 1 generic parameter: `T`
help: add missing generic argument
    |
15  | fn foo<T: Foo>(_x: T) -> Option<T, T:Assoc> {
    |                                 ++
error[E0229]: associated type bindings are not allowed here
  --> src/lib.rs:15:33
   |
15 | fn foo<T: Foo>(_x: T) -> Option<T:Assoc> {
   |                                 ^^^^^^^ associated type not allowed here
Some errors have detailed explanations: E0107, E0229, E0658.
For more information about an error, try `rustc --explain E0107`.
error: could not compile `playground` due to 3 previous errors
Ideally the first error should have a hint that Assoc is also the name of an associated type on T and point to the single colon : with a suggestion to change it to a double colon to access the associated type.
Output is identical across stable 1.56.1, 1.57.0-beta.7, and 1.58 nightly 2021-11-24
KSBilodeau, estebank, not-my-profile and cujomalainey
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.