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

std::fmt::Pointer should be implemented for pointers to T: ?Sized #30427

Closed
benw opened this issue Dec 17, 2015 · 4 comments
Closed

std::fmt::Pointer should be implemented for pointers to T: ?Sized #30427

benw opened this issue Dec 17, 2015 · 4 comments

Comments

@benw
Copy link

benw commented Dec 17, 2015

Example:

fn main() {
    let x: Box<std::fmt::Debug> = Box::new("hello");
    println!("{:p}", x);
    // error: the trait `core::marker::Sized` is not implemented for the type `core::fmt::Debug`
}

I think Pointer should be impled as follows:

impl<T: ?Sized> Pointer for Box<T>

and likewise for borrowed refs, raw pointers, Arc etc.

@sfackler
Copy link
Member

Boxed trait objects contain two pointers - one to the object and the other to the vtable. Should only one be printed?

@benw
Copy link
Author

benw commented Dec 17, 2015

Oh, that is a very good point, thanks. This is not nearly as obvious as I thought. I was assuming that the data pointer would be printed, but if you see any possible downside to implementing that, then I'll be entirely satisfied with transmuting to TraitObject and printing the data field for myself.

@bluss
Copy link
Member

bluss commented Dec 22, 2015

Considering trait pointers can be cast to thin pointers, whatever pointer that yields is the one.

@durka
Copy link
Contributor

durka commented Oct 1, 2016

This was fixed by #31479.

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

No branches or pull requests

5 participants