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

fmt: impl fmt::Pointer for smart pointer types #24144

Merged
merged 1 commit into from
Apr 9, 2015

Conversation

richo
Copy link
Contributor

@richo richo commented Apr 7, 2015

I believe this should fix the issue. Opening a PR to ensure noone duplicates effort, I'm running check now.

Closes #24091

@rust-highfive
Copy link
Collaborator

r? @pcwalton

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

@richo
Copy link
Contributor Author

richo commented Apr 7, 2015

This builds and does something reasonable on my machine. Is it worth adding a test?

Also, are there any other smart pointer types that I should impl for? The only other one that looks relevant is P in rustc that would be useful for shotgun debugging, and perhaps Box ?

@richo
Copy link
Contributor Author

richo commented Apr 7, 2015

Bonus impls for the other smart pointers I could find

@@ -276,6 +276,13 @@ impl<T: fmt::Debug + ?Sized> fmt::Debug for Box<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> fmt::Pointer for Box<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Pointer::fmt(&*self, f)
Copy link
Member

Choose a reason for hiding this comment

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

I think that this is infinitely recursive, did you mean &**self?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Is Box specialcased in some way in the compiler? I can't seem to extract the Unique within using tuple access or a destructuring match.

 expected `Box<T>`,
    found `boxed::Box<_>`
(expected box,
    found struct `boxed::Box`) [E0308]
/Users/richo/code/ext/rust/src/liballoc/boxed.rs:282             &Box(uniq) => fmt::Pointer::fmt(&uniq, f)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah Box is pretty special, and I'm not actually sure the definition has much bearing on what you can do with the type itself. You'll probably want to pull out &T from &Box<T> and then format that.

@alexcrichton
Copy link
Member

Could you add a smoke test for the Box, Rc, and Arc impls as well?

@alexcrichton alexcrichton assigned alexcrichton and unassigned pcwalton Apr 7, 2015
@richo
Copy link
Contributor Author

richo commented Apr 7, 2015

Sure, I'll work out how I goofed box and add the test.

@richo richo changed the title alloc: impl fmt::Pointer for Rc and Arc fmt: impl fmt::Pointer for smart pointer types Apr 8, 2015
@richo
Copy link
Contributor Author

richo commented Apr 8, 2015

I added a test, and made it pad pointers to native pointer width if no format is specified, which I bellieve to be correct. Let me know if I should rip that off though.

Make check is running on my machine, but I tested that the test case added works with a stage1.

r? @alexcrichton

@richo
Copy link
Contributor Author

richo commented Apr 8, 2015

(make check passes locally, on osx)

let old_width = f.width;
if let None = f.width {
f.width = POINTER_PADDING;
}
Copy link
Member

Choose a reason for hiding this comment

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

Could this change be left to another PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, np.

@richo
Copy link
Contributor Author

richo commented Apr 8, 2015

Rebased, this is now only the fmt::Pointer implementation

@richo richo mentioned this pull request Apr 8, 2015
@alexcrichton
Copy link
Member

Thanks! Could you also squash the commits together? Other than that r=me

@richo
Copy link
Contributor Author

richo commented Apr 8, 2015

Done, thanks!

@alexcrichton
Copy link
Member

@bors: r+ a329a61

@bors
Copy link
Contributor

bors commented Apr 8, 2015

⌛ Testing commit a329a61 with merge 6436e34...

bors added a commit that referenced this pull request Apr 8, 2015
~~I believe this should fix the issue. Opening a PR to ensure noone duplicates effort, I'm running check now.~~

Closes #24091
@bors bors merged commit a329a61 into rust-lang:master Apr 9, 2015
bors added a commit that referenced this pull request Apr 10, 2015
This pads out the printing of pointers to their native width.

Extracted from and rebased on top of #24144
bors added a commit that referenced this pull request Apr 11, 2015
This pads out the printing of pointers to their native width.

Extracted from and rebased on top of #24144
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.

Smart pointer types should have a fmt::Pointer implementation
5 participants