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

impl<T> Format for {*const, *mut} T where T: Format + ?Sized #464

Merged
merged 2 commits into from May 12, 2021

Conversation

Urhengulas
Copy link
Member

  • This behaves like std::fmt::Debug by printing the address as hexadecimal.
  • The *self as *const () as usize is also used at rust/library/core/src/fmt/mod.rs#L2130.
  • The as *const (), seems to be required cause else rustc complains with "casting *const T as usize is invalid, cast through a thin pointer first".

Fixes #442

@Urhengulas Urhengulas requested a review from japaric May 10, 2021 14:36
Copy link
Member

@japaric japaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Looks good to me. Could you also add a snapshot test for this? (you can create a raw pointer with 0xaabbccdd as *const u8). You can send this to bors afterwards.

@Urhengulas
Copy link
Member Author

Nice! Looks good to me. Could you also add a snapshot test for this? (you can create a raw pointer with 0xaabbccdd as *const u8). You can send this to bors afterwards.

Will do :) Do you know why the snapshot tests are failing btw?

@japaric
Copy link
Member

japaric commented May 12, 2021

Do you know why the snapshot tests are failing btw?

#467

This behaves like `std::fmt::Debug` by printing the address as hex.
@Urhengulas
Copy link
Member Author

bors r+

@bors
Copy link
Contributor

bors bot commented May 12, 2021

Build succeeded:

@bors bors bot merged commit 6c3b287 into main May 12, 2021
@bors bors bot deleted the format-for-raw-pointers branch May 12, 2021 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement Format for raw pointers
2 participants