Repository navigation
Make unique_ptr::as_pin and virtual_unique_ptr::as_pin panic on null instead of returning Option. - #2901
Open
copybara-service[bot] wants to merge 1 commit into
Open
Make unique_ptr::as_pin and virtual_unique_ptr::as_pin panic on null instead of returning Option.#2901copybara-service[bot] wants to merge 1 commit into
unique_ptr::as_pin and virtual_unique_ptr::as_pin panic on null instead of returning Option.#2901copybara-service[bot] wants to merge 1 commit into
Conversation
copybara-service
Bot
force-pushed
the
test_1017592150
branch
7 times, most recently
from
November 12, 2026 03:41
86708d2 to
2df034b
Compare
…ull instead of returning `Option`. With `nonnull_smart_pointers`, nullable C++ `std::unique_ptr`s bind in Rust as `Nullable<unique_ptr<T>>` (or `Nullable<virtual_unique_ptr<T>>`), while bare `unique_ptr<T>` and `virtual_unique_ptr<T>` represent pointers that are non-null unless moved-from or constructed via `from_raw(null)`. `Deref`, `DerefMut`, `as_mut`, `into_box`, `into_pin_box`, and `into_inner` already panic on null; only `as_pin` returned `Option<Pin<&mut T>>`, forcing every `!Unpin` caller to unwrap a `None` that cannot occur. Change `unique_ptr::as_pin` and `virtual_unique_ptr::as_pin` to return `Pin<&mut T>` directly and panic on null (`"dereferencing a null unique_ptr"` / `"dereferencing a null virtual_unique_ptr"`), matching `as_mut` and `Deref`. Callers that legitimately hold a possibly-null bare `unique_ptr` can check with `unique_ptr::is_null` first, or use `Nullable<unique_ptr<T>>`. PiperOrigin-RevId: 1017592150
copybara-service
Bot
force-pushed
the
test_1017592150
branch
from
November 12, 2026 15:14
2df034b to
6ab22e9
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make
unique_ptr::as_pinandvirtual_unique_ptr::as_pinpanic on null instead of returningOption.With
nonnull_smart_pointers, nullable C++std::unique_ptrs bind in Rust asNullable<unique_ptr<T>>(orNullable<virtual_unique_ptr<T>>), while bareunique_ptr<T>andvirtual_unique_ptr<T>represent pointers that are non-null unless moved-from or constructed viafrom_raw(null).Deref,DerefMut,as_mut,into_box,into_pin_box, andinto_inneralready panic on null; onlyas_pinreturnedOption<Pin<&mut T>>, forcing every!Unpincaller to unwrap aNonethat cannot occur.Change
unique_ptr::as_pinandvirtual_unique_ptr::as_pinto returnPin<&mut T>directly and panic on null ("dereferencing a null unique_ptr"/"dereferencing a null virtual_unique_ptr"), matchingas_mutandDeref. Callers that legitimately hold a possibly-null bareunique_ptrcan check withunique_ptr::is_nullfirst, or useNullable<unique_ptr<T>>.