-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking issue for NonZero
/Unique
/Shared
stabilization
#27730
Comments
I'm not a fan of NonZero. I would like a more robust system that can hook into the things described in rust-lang/rfcs#1230. Unique is great, but I would like to rename it to Owned to better reflect what its actual semantics are (e.g. it's fine to have other pointers into it just like it's fine for Box). I would like to add a Shared equivalent for Rc/Arc to use. This is blocked by #26905 |
NonZero
/Unique
stabilizationNonZero
/Unique
/Shared
stabilization
I expanded this issue to cover the new |
CC @SimonSapin Does Shared/Unique cover all your NonZero usecases? |
I commented about this in #29110, reposting here for visibility: The They also allow writing
|
@eddyb alternatively, we could just promote these types to compiler primitives, right? Have them coerce to raw pointers or summat? This may also improve debug perf, as there's less abstraction in the way if it's really "just" a raw pointer, and not a Foo(Bar(*const T)) that is accessed through two levels of methods. |
I agree with @eddyb's comment about using a |
The libs team decided to not move these APIs into FCP this cycle because the |
(Answering with a small delay… :)) Unfortunately no. We would like to use |
I don't know if this is the right place to comment, but I'm binding some C code and Unique appears perfect - except that it exposes the unsafe rather than that being internal - meaning that I need a further wrapper around it - since I know the C ptr in question isn't going to be freed randomly, and I know that its not null, I want to hide the unsafe entirely from further out users. |
@rbtcollins My suggestion would be to write a wrapper struct that has a |
N.B. |
If we keep NonZero or something like it, I would love a safe (checked) way to construct one. Currently the single line of unsafe code in Serde is constructing a NonZero. if value == Zero::zero() {
return Err(Error::invalid_value("expected a non-zero value"))
}
unsafe {
Ok(NonZero::new(value))
} |
I'm making changes to this API in this PR #41064 |
I was hoping to land #46952 and get |
Assuming you mean via a hidden private |
Right, I meant "remove" as far as the public API is concerned. We can have a private generic type (with or without a trait bound) in the implementation, or whatever’s easier to maintain for the compiler. |
`Shared` is now a deprecated `type` alias. CC rust-lang#27730 (comment)
Rename std::ptr::Shared to NonNull and stabilize it This implements the changes proposed at #27730 (comment): > * Rename `Shared<T>` to `NonNull<T>` and stabilize it. (Being in the `ptr` module is enough to say that it’s a pointer. I’m not very attached to this specific name though.) > * Rename `Box<T>` methods ~~`from_unique`~~/`into_unique` to ~~`from_nonnull`~~/`into_nonnull` (or whatever names are deemed appropriate), replace `Unique<T>` with `NonNull<T>` in their signatures, and stabilize them. > * Replace `Unique<T>` with `NonNull<T>` in the signatures of methods of the `Alloc` trait. > * Mark `Unique` “permanently-unstable” by replacing remaining occurrences of `#[unstable(feature = "unique", issue = "27730")]` with: > > ```rust > #[unstable(feature = "ptr_internals", issue = "0", reason = "\ > use NonNull instead and consider PhantomData<T> (if you also use #[may_dangle]), \ > Send, and/or Sync")] > ``` > > (Maybe the `reason` string is only useful on the struct definition.) Ideally it would be made private to some crate instead, but it needs to be used in both liballoc and libstd. > * (Leave `NonZero` and `Zeroable` unstable for now, and subject to future bikeshedding.)
Shared is now renamed NonNull and stable; Unique is a permanently-unstable internal implementation detail of std: #47631 This only leaves NonZero for this tracking issue, which is now mostly only useful for integers. I just published rust-lang/rfcs#2307 which propose adding 12 concrete types like |
Also some NonNull follow up: #47631 |
`Shared` is now a deprecated `type` alias. CC rust-lang/rust#27730 (comment)
Add some APIs to ptr::NonNull and fix `since` attributes This is a follow-up to its stabilization in rust-lang#46952. Tracking issue: rust-lang#27730. * These trait impls are insta-stable: `Hash`, `PartialEq`, `Eq`, `PartialOrd` and `Ord`. * The new `cast<U>() -> NonNull<U>` method is `#[unstable]`. It was proposed in rust-lang#46952 (comment).
Implementation PR, ready to merge: #48265
After whatever time is appropriate for the deprecation period of unstable features, we can land SimonSapin#1 to make |
Hm, this probably way too late, but are we sure that the name should be Would just a EDIT: nvm, see that this already was discussed in another issue: #46952 (comment) |
The enum optimization is my motivation for pushing this feature to stabilization, FWIW. I think you could already get covariance before by using |
Add 12 num::NonZero* types for primitive integers, deprecate core::nonzero RFC: rust-lang/rfcs#2307 Tracking issue: ~~rust-lang#27730 rust-lang#49137 Fixes rust-lang#27730
Add 12 num::NonZero* types for primitive integers, deprecate core::nonzero RFC: rust-lang/rfcs#2307 Tracking issue: ~~rust-lang#27730 rust-lang#49137 Fixes rust-lang#27730
Tracking issue for the new |
We currently have three internal types,
NonZero
,Unique
andShared
, that are very useful when working with unsafe Rust code. Ultimately, the hope is to have a clear vision for semi-high-level, but unsafe programming using types like these.None of the current APIs have gone through the RFC process, and a comprehensive RFC should be written before any stabilization is done.
cc @gankro
The text was updated successfully, but these errors were encountered: