Skip to content

#[derive(PartialEq)] fails to compile with an Arc<Trait> field #39128

@sfackler

Description

@sfackler
use std::sync::Arc;
use std::fmt;
use std::cmp::PartialEq;

trait Foo {}

impl PartialEq for Foo {
    fn eq(&self, other: &Foo) -> bool {
        true
    }
}

type Bar = Arc<Foo>;

#[derive(PartialEq)]
struct Baz {
    bar: Bar,
}

fn main() {}
error[E0507]: cannot move out of borrowed content
  --> foo.rs:17:5
   |
17 |     bar: Bar,
   |     ^^^^^^^^ cannot move out of borrowed content

error[E0507]: cannot move out of borrowed content
  --> foo.rs:17:5
   |
17 |     bar: Bar,
   |     ^^^^^^^^ cannot move out of borrowed content

error: aborting due to 2 previous errors

Expanded:

#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std as std;
use std::sync::Arc;
use std::fmt;
use std::cmp::PartialEq;

trait Foo { }

impl PartialEq for Foo {
    fn eq(&self, other: &Foo) -> bool { true }
}

type Bar = Arc<Foo>;

struct Baz {
    bar: Bar,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Baz {
    #[inline]
    fn eq(&self, __arg_0: &Baz) -> bool {
        match *__arg_0 {
            Baz { bar: ref __self_1_0 } =>
            match *self {
                Baz { bar: ref __self_0_0 } =>
                true && (*__self_0_0) == (*__self_1_0),
            },
        }
    }
    #[inline]
    fn ne(&self, __arg_0: &Baz) -> bool {
        match *__arg_0 {
            Baz { bar: ref __self_1_0 } =>
            match *self {
                Baz { bar: ref __self_0_0 } =>
                false || (*__self_0_0) != (*__self_1_0),
            },
        }
    }
}

fn main() { }

Metadata

Metadata

Assignees

No one assigned

    Labels

    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