-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement fmt::Pointer for pointers to unsized types #31479
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Which half of the fat pointer will this print? |
The cast to thin pointer should give you the data pointer. However it doesn't matter which — Rust has already decided that you can cast a fat pointer to a thin pointer, and whatever it thinks the result of that is, it's the one we should print too 😄 |
I added a test to ensure you get the data pointer for |
Thanks @kamalmarhubi! I think @bluss's reasoning is sound, so these all likely look good to me. I'd like to run it by the libs team, however, just to make sure as these'll be insta-stable once landed. cc @rust-lang/libs |
This allows printing pointers to unsized types with the {:p} formatting directive. The following impls are extended to unsized types: - impl<'a, T: ?Sized> Pointer for &'a T - impl<'a, T: ?Sized> Pointer for &'a mut T - impl<T: ?Sized> Pointer for *const T - impl<T: ?Sized> Pointer for *mut T - impl<T: ?Sized> fmt::Pointer for Box<T> - impl<T: ?Sized> fmt::Pointer for Rc<T> - impl<T: ?Sized> fmt::Pointer for Arc<T>
8fe0913
to
c5f73ed
Compare
Thanks @alexcrichton! In the meantime, squashed and rebased. |
The libs team discussed this during triage today and the discussion was to merge. Thanks again for the PR @kamalmarhubi! |
This allows printing pointers to unsized types with the {:p} formatting directive. The following impls are extended to unsized types: - impl<'a, T: ?Sized> Pointer for &'a T - impl<'a, T: ?Sized> Pointer for &'a mut T - impl<T: ?Sized> Pointer for *const T - impl<T: ?Sized> Pointer for *mut T - impl<T: ?Sized> fmt::Pointer for Box<T> - impl<T: ?Sized> fmt::Pointer for Rc<T> - impl<T: ?Sized> fmt::Pointer for Arc<T>
This allows printing pointers to unsized types with the {:p} formatting
directive. The following impls are extended to unsized types: