Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lcnr opened this issue Oct 6, 2022 · 2 comments
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) A-coherence Area: Coherence A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Oct 6, 2022

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.

@lcnr lcnr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 6, 2022
@in42
Copy link
Contributor

in42 commented Oct 7, 2022

@rustbot claim

@fmease fmease added the A-coherence Area: Coherence label Sep 28, 2024
@fmease
Copy link
Member

fmease commented Sep 28, 2024

The snippet compiles since #117164 (1.80) as <() as Trait>::Assoc now gets normalized. Closing as not planned as a diagnostic is no longer necessary.

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2024
@fmease fmease added the A-associated-items Area: Associated items (types, constants & functions) label Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-coherence Area: Coherence A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants