Skip to content

Error on deriving PartialEq on Foo and then implementing it for dyn Foo #78808

@frostblooded

Description

@frostblooded

I tried this code:

trait Foo {}

impl PartialEq for dyn Foo {
    fn eq (self: &'_ Self, _: &'_ Self) -> bool { false }
}

#[derive(PartialEq)]
struct Bar {
    __: ::std::rc::Rc<dyn Foo>,
}
fn main () {}

I expected to see this happen:

A working PartialEq derived implementation for Bar.

Instead, this happened:
An error was thrown:

error[E0507]: cannot move out of `*__self_1_0` which is behind a shared reference
 --> src/main.rs:9:5
  |
9 |     __: ::std::rc::Rc<dyn Foo>,
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ move occurs because `*__self_1_0` has type `Rc<dyn Foo>`, which does not implement the `Copy` trait
  |
  = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0507`.
error: could not compile `playground`

To learn more, run the command again with --verbose.

Meta

The bug is present on nightly and stable in the two versions I tried:
rustc --version --verbose:

rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
binary: rustc
commit-hash: ffa2e7ae8fbf9badc035740db949b9dae271c29f
commit-date: 2020-10-24
host: x86_64-pc-windows-msvc
release: 1.49.0-nightly
LLVM version: 11.0

rustc --version --verbose:

rustc 1.46.0 (04488afe3 2020-08-24)
binary: rustc
commit-hash: 04488afe34512aa4c33566eb16d8c912a3ae04f9
commit-date: 2020-08-24
host: x86_64-pc-windows-msvc
release: 1.46.0
LLVM version: 10.0

Backtrace doesn't show anything different than the error.
Here is the reproducable code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a4d7bd689ed0687e24533f956f7a5971
@danielhenrymantilla seemed interested in the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.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