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

In core::ptr, weird thing about impl<T: ?Sized> #24794

Closed
strega-nil opened this issue Apr 24, 2015 · 3 comments
Closed

In core::ptr, weird thing about impl<T: ?Sized> #24794

strega-nil opened this issue Apr 24, 2015 · 3 comments

Comments

@strega-nil
Copy link
Contributor

So the implementation itself is for T: ?Sized, but the actual functions themselves are for T: Sized.

i.e.

#[lang = "const_ptr"]
impl<T: ?Sized> *const T {
    #[inline]
    pub fn is_null(self) -> bool where T: Sized {
        self == 0 as *const T
    }
}

This makes absolutely no sense. First: why would you impl<T: ?Sized> and then not allow you to call any functions on T: !Sized. Second, why can you only call is_null on T: Sized? Makes absolutely no sense.

@alexcrichton
Copy link
Member

This is actually currently intentional! The T: ?Sized means that the impl block is maximally generic by default (we only have one). Each method then adds bounds as necessary, and in this case the is_null method currently requires that T is sized.

At the time this function was written, it was an ICE if T was not sized (hence *const T was a fat pointer). It is intended that one day that ICE and/or restriction will be lifted so this method will not have a T: Sized bound.

@strega-nil
Copy link
Contributor Author

Ah okay cool. We should probably make a comment about that?

@alexcrichton
Copy link
Member

I'd be down with that!

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

2 participants