You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
This would automatically be usable as NonZero<c_char> = NonZeroI8/NonZeroU8 (based on platform).
Note we don't need to make any underlying trait publicly accessible. This is not for writing generic code over all different nonzero types. It is just for saner spelling of the type names.
Reacted by Jonas Platte, Ashley Mannix, Trevor Gross, Corey Farwell, Nikolai Vazquez and Petr Portnov | PROgrm_JARvis
IMO introducing AtomicT/NonZeroT replacing Atomic<T>/NonZero<T> are the gravest API mistake Rust has ever made so +1 to introducing NonZero<T> again.
The 12 NonZeroT types are introduced in rust-lang/rfcs#2307 was to sidestep the question what should happen to NonZero<CustomType>, taking the precedent of AtomicT (but disregarding Wrapping<T>).
One problem of the current API is that it is unclear what happens or what should happen to NonZero<T> or Option<NonZero<T>> when T is some type other than a raw pointer or a primitive integer. In particular, crates outside of std can implement Zeroable for their arbitrary types since it is a public trait.
To avoid this question entirely, this RFC proposes replacing the generic type and trait with twelve concrete types in std::num, one for each primitive integer type. This is similar to the existing atomic integer types like std::sync::atomic::AtomicU32.
The Motivation no longer applies since, as demonstrated in in #88990, we can make the bounding trait IntegerPrimitive (previously Zeroable) a private/sealed trait. During FCP SimonSapin did mention (in rust-lang/rfcs#2307 (comment) and rust-lang/rfcs#2307 (comment)) why this route was not considered, mainly because of type checker bugs and personal taste. It was agreed in rust-lang/rfcs#2307 (comment) that the question won't block the FCP-merge. Yet the question of generics was not checkboxed in #49137 before stabilization of NonZeroT.
Now that this issue shows that generics is greatly favored, I think we should better do it properly by turning NonZero<T> back to a struct, and NonZeroT direct type aliases, rather than the current implementation that NonZeroT are concrete types and NonZero<T> being an alias going jumping through associated types.
Activity
tesuji commentedon Feb 21, 2021
joshtriplett commentedon Aug 25, 2021
FCP for stabilization:
@rfcbot merge
rfcbot commentedon Aug 25, 2021
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:
Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
dtolnay commentedon Aug 26, 2021
I can't say that I am thrilled about Pascal_snake_concatwords-case. Can we reconsider doing a generic type alias instead?
This would automatically be usable as
NonZero<c_char>= NonZeroI8/NonZeroU8 (based on platform).Note we don't need to make any underlying trait publicly accessible. This is not for writing generic code over all different nonzero types. It is just for saner spelling of the type names.
joshtriplett commentedon Aug 26, 2021
If that kind of generic is possible, I'm all for it. Is it?
Amanieu commentedon Aug 26, 2021
I also think that these names are very ugly and would vastly prefer a generic
NonZerotype based on a sealed trait.@rfcbot concern generic NonZero
kennytm commentedon Sep 17, 2021
IMO introducing
AtomicT/NonZeroTreplacingAtomic<T>/NonZero<T>are the gravest API mistake Rust has ever made so +1 to introducingNonZero<T>again.The 12
NonZeroTtypes are introduced in rust-lang/rfcs#2307 was to sidestep the question what should happen toNonZero<CustomType>, taking the precedent ofAtomicT(but disregardingWrapping<T>).The Motivation no longer applies since, as demonstrated in in #88990, we can make the bounding trait
IntegerPrimitive(previouslyZeroable) a private/sealed trait. During FCP SimonSapin did mention (in rust-lang/rfcs#2307 (comment) and rust-lang/rfcs#2307 (comment)) why this route was not considered, mainly because of type checker bugs and personal taste. It was agreed in rust-lang/rfcs#2307 (comment) that the question won't block the FCP-merge. Yet the question of generics was not checkboxed in #49137 before stabilization ofNonZeroT.Now that this issue shows that generics is greatly favored, I think we should better do it properly by turning
NonZero<T>back to a struct, andNonZeroTdirect type aliases, rather than the current implementation thatNonZeroTare concrete types andNonZero<T>being an alias going jumping through associated types.the inherent functions
leading_zeros,trailing_zeros,{checked,saturating,unchecked}_{add,mul,pow},checked_next_power_of_two,abs,{checked,overflowing,saturating,wrapping,unsigned}_abs,is_power_of_twostill require per-instance impl by macro.joshtriplett commentedon Oct 5, 2021
I'd be happy to review a pull request adding a generic
NonZerobased on a sealed trait.joshtriplett commentedon Oct 5, 2021
Cancelling in favor of generic NonZero.
@rfcbot cancel
rfcbot commentedon Oct 5, 2021
@joshtriplett proposal cancelled.
CAD97 commentedon Jul 17, 2022
Just as a note: std is missing a reëxport of these names from core.
reitermarkus commentedon Aug 11, 2022
I had a go at implementing a generic
NonZerotype here #100428.briansmith commentedon Nov 27, 2023
NonZero_c_size_tandNonZero_c_ptrdiff_tare missing fromcore::ffi.Rollup merge of rust-lang#118665 - dtolnay:signedness, r=Nilstrieb
Unrolled build for rust-lang#118665
Rollup merge of #118665 - dtolnay:signedness, r=Nilstrieb
Rollup merge of rust-lang#120295 - reitermarkus:remove-ffi-nonzero, r…
Unrolled build for rust-lang#120295
dtolnay commentedon Jan 30, 2024
Superseded by #120257.