Skip to content

Incorrect suggestion when calling an associated type with a type ancor #142473

Closed
@WaffleLapkin

Description

@WaffleLapkin

Code

struct T();

trait Trait {
    type Assoc;
    
    fn f();
}

impl Trait for () {
    type Assoc = T;

    fn f() {
        <Self>::Assoc()
    }
}

fn main() {}

Current output

error[E0599]: no associated item named `Assoc` found for unit type `()` in the current scope
  --> src/main.rs:13:17
   |
13 |         <Self>::Assoc()
   |                 ^^^^^ associated item not found in `()`
   |
help: to construct a value of type `T`, use the explicit path
   |
13 -         <Self>::Assoc()
13 +         <T()
   |

Desired output

error[E0599]: no associated item named `Assoc` found for unit type `()` in the current scope
  --> src/main.rs:13:17
   |
13 |         <Self>::Assoc()
   |                 ^^^^^ associated item not found in `()`
   |
help: to construct a value of type `T`, use the explicit path
   |
13 -         <Self>::Assoc()
13 +         T()
   |

Rationale and extra context

<T() is not valid syntax; T() is.

Rust Version

1.89.0-nightly (2025-06-11 e703dff8fe220b78195c)

Metadata

Metadata

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

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions