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

Implement fmt::Pointer for pointers to unsized types #31479

Merged
merged 1 commit into from
Feb 11, 2016

Conversation

kamalmarhubi
Copy link
Contributor

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
  • impl<T: ?Sized> fmt::Pointer for Rc
  • impl<T: ?Sized> fmt::Pointer for Arc

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@sfackler
Copy link
Member

sfackler commented Feb 8, 2016

Which half of the fat pointer will this print?

@bluss
Copy link
Member

bluss commented Feb 8, 2016

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 😄

@kamalmarhubi
Copy link
Contributor Author

I added a test to ensure you get the data pointer for &str and &[u8].

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Feb 8, 2016
@alexcrichton
Copy link
Member

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>
@kamalmarhubi
Copy link
Contributor Author

Thanks @alexcrichton! In the meantime, squashed and rebased.

@alexcrichton
Copy link
Member

The libs team discussed this during triage today and the discussion was to merge. Thanks again for the PR @kamalmarhubi!

@bors: r+ c5f73ed

@bors
Copy link
Contributor

bors commented Feb 11, 2016

⌛ Testing commit c5f73ed with merge 106070b...

bors added a commit that referenced this pull request Feb 11, 2016
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants