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

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

Closed
cafce25 opened this issue Jul 30, 2024 · 0 comments · Fixed by #128391
Labels
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

@cafce25
Copy link
Contributor

cafce25 commented Jul 30, 2024

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

@cafce25 cafce25 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 Jul 30, 2024
@fmease fmease added the A-coherence Area: Coherence label Aug 8, 2024
@bors bors closed this as completed in 21c57f5 Oct 17, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 17, 2024
Rollup merge of rust-lang#128391 - cafce25:issue-128390, r=lcnr

Change orphan hint from "only" to "any uncovered type inside..."

Fix rust-lang#128390
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

Successfully merging a pull request may close this issue.

2 participants