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

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

Closed
pwnorbitals opened this issue Apr 16, 2021 · 2 comments
Closed
Labels
C-bug Category: This is a bug.

Comments

@pwnorbitals
Copy link

pwnorbitals commented Apr 16, 2021

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

@pwnorbitals pwnorbitals added the C-bug Category: This is a bug. label Apr 16, 2021
@pwnorbitals pwnorbitals changed the title Unable to easily check for equality between trait objects within an Arc? Unable to easily check for equality between trait objects within an Arc Apr 16, 2021
@jonas-schievink
Copy link
Contributor

duplicate of #63021

@pwnorbitals
Copy link
Author

Then this would in turn be a duplicate of #46139

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants