-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Add Option::unwrap_unchecked #48278
Copy link
Copy link
Closed
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: 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.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: 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.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Now that
NonNullhas been added andOption<NonNull<T>>is preferred over*mut T, if you have code that used to know that a*mut Twas non-null and dereferenced it, you now know that yourOption<NonNull<T>>isSomeand can call.unwrap()on it. However,.unwrap()can incur runtime overhead that dereferencing*mut Tnever 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_uncheckedmethod toOptionthat returns aTby simply assuming that theOptionis currentlySome(T).