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 deriving PartialEq in a struct with Box<Trait> #47823

Closed
itaibn opened this issue Jan 28, 2018 · 3 comments
Closed

Error deriving PartialEq in a struct with Box<Trait> #47823

itaibn opened this issue Jan 28, 2018 · 3 comments

Comments

@itaibn
Copy link

itaibn commented Jan 28, 2018

Code:

pub trait MyTrait {}

impl PartialEq for Box<MyTrait> {
    fn eq(&self, _: &Box<MyTrait>) -> bool {
        false
    }
}

#[derive(PartialEq)]
pub struct MyType(Box<MyTrait>);

fn main() {}

Output:

   Compiling playground v0.0.1 (file:///playground)
error[E0507]: cannot move out of borrowed content
  --> src/main.rs:10:19
   |
10 | pub struct MyType(Box<MyTrait>);
   |                   ^^^^^^^^^^^^^ cannot move out of borrowed content

error: aborting due to 2 previous errors

error: Could not compile `playground`.

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

Three problems:

  • The compiler reports that there are two errors, but it only lists one. (This problem does not appear in the current Nightly compiler, only in Beta and Stable.)

  • The error message doesn't fit with the span provided. This error is usually associated with a statement or expression but here is given for a struct component.

  • I don't see why the derive should not work.

Searching for similar issues, this one may be a duplicate/combination of #39128 and #31740.

@dtolnay
Copy link
Member

dtolnay commented Jan 28, 2018

Thanks! I left a comment in #39128 (originally reported for Arc<Trait>) that the same bug happens for Box<Trait> as well.

@TimNN
Copy link
Contributor

TimNN commented Jan 30, 2018

Closing as duplicate of #47823.

Edit: Ugh... no idea what went wrong here... 😕 😳

@dtolnay dtolnay closed this as completed Jan 30, 2018
@dtolnay
Copy link
Member

dtolnay commented Jan 30, 2018

*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

3 participants