Skip to content

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

@glandium

Description

@glandium
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)

Activity

glandium

glandium commented on Feb 13, 2018

@glandium
ContributorAuthor

duplicate of #24183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @glandium

        Issue actions

          T: Sized bounds on methods of T: ?Sized impls are omitted in the docs · Issue #48176 · rust-lang/rust