Skip to content

Confusing diagnostic when attempting to implementing trait for tuple #67535

Closed
@varkor

Description

@varkor
impl std::ops::AddAssign for () {
    fn add_assign(&self, other: ()) -> () {
        ()
    }
}

produces:

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

Notice how it highlights std::ops::AddAssign and says this is not defined in the current crate because tuples are always foreign, despite AddAssign have nothing to do with tuples.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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