Closed
Description
This is a tracking issue for the RFC "Add std::num::NonZeroU32 and friends, deprecate core::nonzero" (rust-lang/rfcs#2307).
Steps:
- Adjust documentation (see instructions on forge)Stabilization PR (see instructions on forge) Stabilize num::NonZeroU* #50808
Unresolved questions:
- Should the signed types be included?Decide on naming --
NonZeroU32
orPositiveU32
? Should theU
be dropped?Should the memory layout of e.g. Option be a language guarantee?Settle issues wrt. const generics before stabilization.
-- We should either end up with a generic type or with a clear explanation of why a generic type can't work or doesn't work well.
Metadata
Metadata
Assignees
Labels
Blocker: Approved by a merged RFC and implemented but not stabilized.Category: An issue tracking the progress of sth. like the implementation of an RFCRelevant to the language teamRelevant to the library API team, which will review and decide on the PR/issue.This issue / PR is in PFCP or FCP with a disposition to merge it.The final comment period is finished for this PR / Issue.
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
num::NonZero* types now have their own tracking issue: rust-lang#49137
SimonSapin commentedon Mar 18, 2018
Implementation PR: #48265
Documentation: @Centril, do doc-comments in this PR look sufficient to you?
My opinion on unresolved questions:
Signed types (e.g.
NonZeroI32
): as discussed in the RFC thread, they are included in the RFC and implementation PR because it was easy and becausecore::nonzero::NonZero<T>
supports them too. I see a downside to having them, but I also haven’t had a use case for them. And they are easy to build outside ofstd
in a crate that uses the unsigned types internally and does the conversion innew
,new_unchecked
, andget
. (Unlike e.g. non-zero integers of different sizes if onlyNonZeroUsize
were available.)Positive*
names: The fact that zero is not positive in English is subtle, and it is not shared by some other languages. (For example zero is both positive and negative in French, and the correct translation for “nombre positif” is “non-negative number”.) I don’t think relying on such a subtlety to communicate the core property of these types is a good idea.Dropping the
U
in names: this is only possible if we also remove the signed types. But even so, I think that including the full name of the type accepted bynew
and returned byget
is desirable.Separate types v.s. one generic type: this was discussed at length in the RFC. The former has precedent with
std::sync::atomic::Atomic*
. The latter brings other unresolved questions that I feel don’t have satisfactory answers: trait bounds on that type parameter, and implementations of relevant traits for composite for types outside ofstd
.SimonSapin commentedon Mar 18, 2018
Making the memory layout of
Option<num::NonZero*>
a language guarantee: I explicitly made the RFC not make this guarantee in order to keep the RFC within the realm of the standard library (and hopefully easier to get accepted). But if @rust-lang/lang feels comfortable making that guarantee, that sounds good to me.Centril commentedon Mar 18, 2018
@SimonSapin
Pretty much, yeah =)
On the unresolved questions:
Maybe we should skip the signed types but add them when someone asks for them with an issue or PR or on IRC (don't need to go to another RFC then...)?
I agree that
NonZeroU32
is best.SimonSapin commentedon Mar 18, 2018
For what it’s worth the implementation of the 6 signed types costs exactly an additional 111 characters in a macro invocation. They’re not a maintenance burden.
Centril commentedon Mar 18, 2018
This is true; but they cost in compile times -- but probably not a noteworthy amount of time.
clarfonthey commentedon Mar 19, 2018
Honestly, compile time of end-user crates matters a lot more than compile time of libstd and co. because for most users libstd will already be compiled. So, even adding a minute of compile time to libstd isn't super bad.
scottmcm commentedon Mar 20, 2018
Sounds like I'm the only one who likes
Positive
, so let's mark that resolved and stick withNonZeroU32
.Maybe just put the signed ones under a different feature gate? That way we'll find out which ones people use, and there's still nobody "attached" to them, stabilize/remove them separately. (Personally I think
0
is a weird hole in a signed type, and would much rather have nice named types for symmetric integers [not INT_MIN] than ones without zero. [Until we get const generics and can make our own holes.])96 remaining items