Skip to content

Type mismatch mentioning trait as type #72217

Closed
@lcnr

Description

@lcnr
trait DynEq {}

impl<'a> PartialEq for &'a (dyn DynEq + 'static) {
    fn eq(&self, _other: &Self) -> bool {
        true
    }
}

impl Eq for &dyn DynEq {}

Causes the following error:

error[E0308]: mismatched types
 --> src/lib.rs:9:6
  |
9 | impl Eq for &dyn DynEq {}
  |      ^^ lifetime mismatch
  |
  = note: expected type `std::cmp::PartialEq`
             found type `std::cmp::PartialEq`
note: the lifetime `'_` as defined on the impl at 9:13...
 --> src/lib.rs:9:13
  |
9 | impl Eq for &dyn DynEq {}
  |             ^
  = note: ...does not necessarily outlive the static lifetime

This is somewhat confusing, especially since std::cmp::PartialEq is not a type.

This issue has been assigned to @ayrtonm via this comment.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.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