Implement core::ops::Deref and DerefMut for Crubit cpp_std::unique_ptr and virtual_unique_ptr, and Deref for shared_ptr. - #1931
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
…ue_ptr` and `virtual_unique_ptr`, and `Deref` for `shared_ptr`. While C++ `std::unique_ptr` is only shallow-const, it is conventionally treated as deep-const. In order for `&unique_ptr<T>` to be usable from Rust, Crubit treats `unique_ptr` as deep-const. Mutating `T` in C++ while Rust has obtained a `&T` derived from `&unique_ptr<T>` will result in undefined behavior. Additionally, Deref and DerefMut will panic if the pointer is null, mirroring the behavior of these types in C++. Non-nullable variants of these types were considered and rejected due to additional complexity (new variant of every type) as well as the poor compatibility of the resulting types with C++ (e.g. non-null variants would be immovable in C++). PiperOrigin-RevId: 974639553
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.
Implement
core::ops::DerefandDerefMutfor Crubitcpp_std::unique_ptrandvirtual_unique_ptr, andDerefforshared_ptr.While C++
std::unique_ptris only shallow-const, it is conventionally treated as deep-const. In order for&unique_ptr<T>to be usable from Rust, Crubit treatsunique_ptras deep-const. MutatingTin C++ while Rust has obtained a&Tderived from&unique_ptr<T>will result in undefined behavior.Additionally, Deref and DerefMut will panic if the pointer is null, mirroring the behavior of these types in C++. Non-nullable variants of these types were considered and rejected due to additional complexity (new variant of every type) as well as the poor compatibility of the resulting types with C++ (e.g. non-null variants would be immovable in C++).