Skip to content

Are the #![feature(layout_for_ptr)] functions sound to call on invalid data pointers? #86602

Open
@repnop

Description

@repnop

Reading the documentation for the #![feature(layout_for_ptr)] functions, it doesn't mention if it accepts invalid data pointer values (e.g. a pointer created with core::ptr::null()), but seems to suggest that it does:

If T is Sized, this function is always safe to call.

but there's a comment mentioning that the pointer must be valid inside the functions, e.g.:

pub const unsafe fn size_of_val_raw<T: ?Sized>(val: *const T) -> usize {
// SAFETY: the caller must provide a valid raw pointer
unsafe { intrinsics::size_of_val(val) }
}

I would think that the answer is yes since its operating on the metadata of the pointer and not the pointer value itself (and with my limited testing, this seems like the current behavior). However, in either case I think its worth explicitly mentioning the validity of the pointer in the documentation for the functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-raw-pointersArea: raw pointers, MaybeUninit, NonNullC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions