Skip to content

Add Option::unwrap_unchecked #48278

Closed
@joshlf

Description

@joshlf

Now that NonNull has been added and Option<NonNull<T>> is preferred over *mut T, if you have code that used to know that a *mut T was non-null and dereferenced it, you now know that your Option<NonNull<T>> is Some and can call .unwrap() on it. However, .unwrap() can incur runtime overhead that dereferencing *mut T never would. Since a lot of performance-critical code is written using raw pointers (and now, NonNull), this runtime overhead may be worth worrying about.

I propose, for these cases, to introduce an unsafe unwrap_unchecked method to Option that returns a T by simply assuming that the Option is currently Some(T).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.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