Skip to content

#[derive(PartialEq)] doesn't compile when fields are Box<Something> with PartialEq for Box<Something> #50985

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

Closed
stepancheg opened this issue May 23, 2018 · 1 comment

Comments

@stepancheg
Copy link
Contributor

trait Foo {
}

// our custom implementation of PartialEq
impl PartialEq for Box<Foo> {
    fn eq(&self, _other: &Self) -> bool {
        unimplemented!()
    }
}


#[derive(PartialEq)]
struct Bar {
    foo: Box<Foo>, // <!-- compilation error here
}


// this version works properly

struct Baz {
    foo: Box<Foo>,
}

// this version works
impl PartialEq for Baz {
    fn eq(&self, other: &Self) -> bool {
        PartialEq::eq(&self.foo, &other.foo)
    }
}

Error is:

error[E0507]: cannot move out of borrowed content
  --> src/main.rs:13:5
   |
13 |     foo: Box<Foo>,
   |     ^^^^^^^^^^^^^ cannot move out of borrowed content

Play: https://play.rust-lang.org/?gist=b2dcd5013fee7a19b46241390a347572&version=stable&mode=debug

@Mark-Simulacrum
Copy link
Member

Duplicate of #39128.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants