Skip to content

failing orphan check with associated types should suggest using the associated type directly. #102734

Closed as not planned
@lcnr

Description

@lcnr
trait Trait {
    type Assoc;
}

struct LocalTy;
impl Trait for () {
    type Assoc = LocalTy;
}

impl PartialEq for <() as Trait>::Assoc {
    fn eq(&self, other: &Self) -> bool {
        true
    }
}

results in

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
  --> src/lib.rs:10:1
   |
10 | impl PartialEq for <() as Trait>::Assoc {
   | ^^^^^---------^^^^^--------------------
   | |    |             |
   | |    |             `<() as Trait>::Assoc` is not defined in the current crate
   | |    `<() as Trait>::Assoc` is not defined in the current crate
   | impl doesn't use only types from inside the current crate
   |
   = note: define and implement a trait or new type instead

ideally it should mention that <() as Trait>::Assoc may actually be local to the current crate and that the user could replace that projection with the associated type itself.

Metadata

Metadata

Assignees

Labels

A-associated-itemsArea: Associated items (types, constants & functions)A-coherenceArea: CoherenceA-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