Skip to content

Error on implementation violating the orphan rules implies all types must be local when one uncovered local type is sufficient. #128390

Closed
@cafce25

Description

@cafce25

Code

impl From<()> for () {
    fn from(_: ()) {}
}

Current output

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

Desired output

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
 --> src/lib.rs:1:1
  |
1 | impl From<()> for () {
  | ^^^^^--------^^^^^--
  | |    |            |
  | |    |            this is not defined in the current crate because tuples are always foreign
  | |    this is not defined in the current crate because this is a foreign trait
  | impl doesn't use any uncovered types from inside the current crate
  |
  = note: define and implement a trait or new type instead

Rationale and extra context

No response

Other cases

No response

Rust Version

Build using the Nightly version: 1.81.0-nightly(2024-07-12 c6727fc9b5c64cefa726) on the playground

Anything else?

The relevant line is here rustc_hir_analysis/messages.ftl#L354

Metadata

Metadata

Assignees

No one assigned

    Labels

    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