Skip to content

Inaccurate diagnostic when using associated type as a value #142797

Open
@tjhance

Description

@tjhance

Code

struct SomeStruct {
    some_field: u64,
}

trait SomeTrait {
    type SomeType;
    fn foo();
}

impl SomeTrait for bool {
    type SomeType = SomeStruct;

    fn foo() {
        let ss = Self::SomeType;
    }
}

fn main() { }

Current output

error[E0599]: no associated item named `SomeType` found for type `bool` in the current scope
  --> test_assoc.rs:14:24
   |
14 |         let ss = Self::SomeType;
   |                        ^^^^^^^^ associated item not found in `bool`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0599`.

Desired output

Rationale and extra context

The error says there is no associated item named SomeType, but this is not true, since (as I understand it) the technical definition of "associated item" includes associated types. I'm not sure what the ideal error message would be, maybe expected value, found associated type (i.e., E0423)?

Other cases

Rust Version

rustc 1.89.0-nightly (255aa2208 2025-06-19)
binary: rustc
commit-hash: 255aa220821c05c3eac7605fce4ea1c9ab2cbdb4
commit-date: 2025-06-19
host: aarch64-apple-darwin
release: 1.89.0-nightly
LLVM version: 20.1.7

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-papercutDiagnostics: An error or lint that needs small tweaks.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