-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Fat pointer trait implementations #28579
Comments
You can "dynamically" |
That's still unstable, and it's still nontrivial to implement Hash. You can do it with unsafe code and size_of, but it's not ideal - this sort of thing should be handled by the standard library so that user code doesn't have to depend on implementation details like the layout of fat pointers. Without sufficiently smart optimizations, it will also generate sub-optimal code. When it's possible to write a generic |
fn check_eq<T: Eq>(t: T) { t == t; }
fn main() {
let x: *mut [u8] = &mut [0,1];
check_eq(x);
} Anyway, why is |
Ah, it doesn't show up in rustdoc. I guess it's implemented internally in the compiler or something?
A truly deep question 💭 |
http://doc.rust-lang.org/std/cmp/trait.Eq.html has
The impl (at https://github.com/rust-lang/rust/blob/master/src/libcore/ptr.rs#L279) just does |
It would be nice to have better primitives for accessing the fields of fat pointers, and at least implement |
Triage: 18 months with no comments. It seems that the original issue is in fact not an issue. Closing! |
Currently
Hash
is only implemented for thin pointers, andEq
/PartialEq
aren't implemented for any pointers (but==
works for all pointers).All of these traits should be implemented for all pointers.
Without this, it's impossible to implement generic reference-equality semantics that support dynamically sized types, even in unsafe code, thanks to #27570. Even with #27570 it will still be impossible to do safely on stable rust, since
raw::TraitObject
is unstable, and even if it were stable, the type system isn't powerful enough to express when to useraw::TraitObject
vs a thin pointer.Fixing this properly will likely require improvements to the type system. Any improvement which solves rust-lang/rfcs#1279 should be enough.
The text was updated successfully, but these errors were encountered: