Skip to content

Unable to easily check for equality between trait objects within an Arc #84239

@pwnorbitals

Description

@pwnorbitals

I tried this code (reference StackOverflow question) :

let a : Arc<dyn SomeTrait> = getA();
let b : Arc<dyn SomeTrait> = getB();

// The following two approaches don't work as expected
let eq1 = std::ptr::eq(a.as_ref(), b.as_ref()); 
let eq2 = Arc::ptr_eq(&a, &b);

I expected to see this happen:
trait object comparison works as expected, with no false positives or false negatives.

Instead, this happened:
see StackOverflow explanation. Fat pointer comparison is a complex topic and I believe it's a papercut issue that the developper has to understand the internals of fat pointer layout to be able to check for equality

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions