-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Compare only the data part of fat pointers #48814
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
Two fat pointers may point to the same data, but with different vtables (the compiler do not guarantee that vtables are unique). Such pointers should be considered equal by std::ptr::eq(), so cast them to thin pointers to compare only their data part. See <rust-lang#48795>.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @BurntSushi (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Slices are also fat pointers and |
@petrochenkov good point, but even in that case, shouldn't they be considered equal by |
The docs state
Which does not talk about fat pointers at all, but only about addresses. The addresses of slices produced by |
This is a breaking change. We'll need to crater this before accepting. cc #36497 (original tracking issue) |
Added to the crater queue. There are two other PRs waiting in queue before this one. @bors try |
⌛ Trying commit 28feb4c with merge 0a34025aebcc507297260f39eadf2f890a098bed... |
☀️ Test successful - status-travis |
Crater run started. |
Hi @pietroalbini (crater requester), @BurntSushi (reviewer)! Crater results are at: http://cargobomb-reports.s3.amazonaws.com/pr-48814/index.html. 'Blacklisted' crates (spurious failures etc) can be found here. If you see any spurious failures not on the list, please make a PR against that file. (interested observers: Crater is a tool for testing the impact of changes on the crates.io ecosystem. You can find out more at the repo if you're curious) |
Ping from triage, @rust-lang/libs ! We haven't heard from @BurntSushi in a while, so I'm going to randomly reassign to... |
As its doc-comments say, the reason If the meaning of raw pointer equality is to be changed, it should be changed in Or maybe a less disruptive change would be to add a new API? (Potentially as a method rather than a free function.) |
I don't think this makes sense, especially not with the change to slice behavior. |
Edit: Oops, my comment above was incorrect. I mistakenly thought this was changing |
Ping from triage, @rust-lang/libs !
We haven't heard from @withoutboats in a while, so I'm going to deliberately reassign to... r? @SimonSapin |
I’ve already said how the PR as-is is insufficient if we want to make any change here. I hear the argument that the current behavior is broken, but changing the meaning of equality for a primitive type seems like a significant enough change that it should probably go through the RFC process. @rom1v, how do you feel about closing this PR for now and writing an RFC? |
I think this is the right thing to do. 👍 However, I never did this and have currently no time to get into this. If someone is interested in writing an RFC, please go ahead. Otherwise, if nothing happens for too long, I will possibly work on it in the future… |
Given this, I'm going to go ahead and close this PR for now to keep things tidy. Thank you very much for your hard work, @rom1v ! |
In fact, comparing the data part only would be unsound in some cases: struct X {}
impl SomeTrait for X { ... }
struct Y { x: X }
impl SomeTrait for Y { ... }
let y = Y { x: X {} }
let a = &y as *const SomeTrait;
let b = &y.x as *const SomeTrait;
println!("{:?} == {:?} : {}", a, b, a == b); (from here) Here,
|
Two fat pointers may point to the same data, but with different vtables (the compiler do not guarantee that vtables are unique).
Such pointers should be considered equal by
std::ptr::eq()
, so cast them to thin pointers to compare only their data part.See #48795.