Skip to content

T: Sized bounds on methods of T: ?Sized impls are omitted in the docs #48176

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

Closed
glandium opened this issue Feb 13, 2018 · 1 comment
Closed

Comments

@glandium
Copy link
Contributor

There are not a lot of those around, according to a quick grep. The vast majority are in core::ptr. Anyways, in e.g. core::ptr, there is:

impl<T: ?Sized> *mut T {
    ...
    pub unsafe fn offset(self, count: isize) -> *const T where T: Sized {
        intrinsics::offset(self, count)
    }
    ....
}

Note that the impl has a T: ?Sized bound, but the offset method has an additional T: Sized bound.

But the corresponding doc says nothing about that bound:
https://doc.rust-lang.org/std/primitive.pointer.html#method.offset-1

which ends up being misleading, since the only bound shown on the page is T: ?Sized.

I hit a surprising

14 |         if ptr.is_null() {
   |                ^^^^^^^ `T` does not have a constant size known at compile-time
   |
   = help: the trait `core::marker::Sized` is not implemented for `T`
   = help: consider adding a `where T: core::marker::Sized` bound

because of that discrepancy (but didn't pick is_null above because it changed in beta/nightly, it doesn't have the T: Sized bound anymore ; offset still does)

@glandium
Copy link
Contributor Author

duplicate of #24183

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

1 participant