-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Deprecate stdlib modules dedicated to numeric constants and move those constants to associated consts #2700
Conversation
Team member @SimonSapin 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. |
Does it really make sense to have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thoughts...
Also, I think it's premature to jump to PFCP so quickly when no discussion has been had at all.
a good rfc requires an explicite list |
I took the links in the motivation section as showing there had been ample discussion elsewhere already. That said, let’s register this as a concern to give more time: @rfcbot concern more discussion before FCP start |
@Ekleog , I have added language to the section on alternatives further elaborating on the rationale here. Updates to the text regarding other concerns are forthcoming, as my busy schedule playing Minecraft with my girlfriend permits. |
While I support deprecation of module-level constants in favor of associated constants (also I think we should add |
UNIX_EPOCH has already been moved: https://doc.rust-lang.org/std/time/struct.SystemTime.html#associatedconstant.UNIX_EPOCH |
Yes, I know. My point is about marking |
Though note that the inability to bring associated items into scope via use std::time::UNIX_EPOCH; ...which, if use std::time::SystemTime;
const UNIX_EPOCH: SystemTime = SystemTime::UNIX_EPOCH; Furthermore, because all primitive types are already in the prelude, doing the same transition for the numeric types as proposed in this RFC would be even easier, requiring only a line such as: use std::i32::MAX; ...to become: const MAX: i32 = i32::MAX; Finally, whereas I can totally see someone wanting to use So while it would be nice to be able to import associated consts, (and associated items in general; has anyone ever submitted an RFC for this?) I don't necessarily think it will be such a hindrance in this case if we chose not to wait until that were possible. |
@bstrie Sure, it seems clear that |
@Centril, note that all the integral modules contain only I'll summarize this discussion and add it to the Drawbacks section. |
# Rationale and alternatives | ||
[rationale-and-alternatives]: #rationale-and-alternatives | ||
|
||
There is an alternative design where the proposed changes are only made to the integral numeric modules in the standard library, leaving alone `f32` and `f64`. Unlike the integral modules, these modules do not contain both constants and redundant associated items. In addition, these two modules contain submodules named `consts`, which contain constants of a more mathematical bent (the sort of thing other languages might put in a `std::math` module). This RFC argues for giving the float modules the same treatment as the integral modules, both since associated consts are "obviously the right thing" in this case and because we do not consider the mathematical/machine constant distinction to be particularly useful or intuitive. In particular, this distinction is not consistent with the existing set of associated functions implemented on `f32` and `f64`, which consist of a mix of both functions concerned with mathematical operations (e.g. `f32::atanh`) and functions concerned with machine representation (e.g. `f32::is_sign_negative`). As noted, if a `math` module existed in Rust's stdlib this would be the natural place to put them, however, such a module does not exist; further, any consideration of this hyptothetical module would, for the sake of consistency, want to also adopt not only the aforementioned mathematical associated functions that currently exist on `f32` and `f64`, but would also want to adopt the integral mathematical functions such as `i32::pow`--all while in some way recreating the module-level distinction between the operations as they exist on the various different numeric types. This is all to say that such a `std::math` module is out of scope for this proposal, in addition to lacking the technical motivation of this proposal. Ultimately, however, leaving `f32` and `f64` along and making the proposed changes only to the integral types would still be considered a success by this RFC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(please use linebreaks or semantic linefeeds...)
This RFC argues for giving the float modules the same treatment as the integral modules, both since associated consts are "obviously the right thing" in this case [...]
Please make an effort beyond "obviously the right thing". It's often not obvious, even if you think it is.
Yes please! I always just type |
Also, f32::PI would be very nice! The chance that someone ever types that intending something other than the mathematical constant Pi seems infinitesimal. I think Pi and other mathematical constants are fundamental enough that they don't deserve being shuffled out of sight to a 'constants' namespace. |
Couldn't deprecation wait til next edition (2021?). But introduce the new names now? |
@SimonSapin I think it's fair to say that the discussion has slowed down at this point. :) |
Indeed! @rfcbot resolve more discussion before FCP start However I think that the regression of not being able to import these constants is a valid concern. At least for the math constants, since for example @rfcbot concern importing @bstrie, What do you think of having the RFC propose adding associated constants now, but only deprecating the other constants after associated items can be imported with I couldn’t find an RFC for that, anyone would like to write it? https://internals.rust-lang.org/t/importing-associated-constants/6610 asked for it, and https://rust-lang.github.io/rfcs/0195-associated-items.html#scoping-of-trait-and-impl-items suggests it as a future extension. |
cc @petrochenkov @rust-lang/lang ^---- |
If this is blocked on the import issue I agree with some other people above that suggest we add the associated constants now and deprecate the module constants when imports are possible. We can deprecate |
Deprecation is just a warning by default right? And all that a person does to fix this particular deprecation is search and replace some paths for some constants? Just do it. Rip the band-aid off. |
Is |
To me "My primary reason for pushing this RFC is that I want writers to not have to think about this issue at all; what means do we have of encouraging writers to use these constants other than deprecation?" argues for not deprecating them immediately, as deprecation forces writers to think about which path they should be using. I am not opposed to soft-deprecating these constants. I would not even be opposed to a deprecation date tied to an edition, with the lint being auto-fixable (with presumably some compiler magic); for that matter if we deprecate them (as I believe is usual) 2-3 releases after the replacements land so that crates on stable can transition without needing But I don't think deprecating anything immediately makes sense, as that makes the transition painful for everyone. |
But it's (1) not actually painful to have a warning (2) totally solvable with search and replace. People aren't being told "use this new function that works slightly differently", it's an identical value just at a new item path. |
You're not wrong that it's likely solvable in an easy way, but to me that doesn't mean we should just deprecate immediately. I don't see any advantage to doing so -- indeed, would be fine with 3 ways to access max/min values ( In any case, I think I've expressed my viewpoint sufficiently and we're spinning at this point. I would personally be in favor of merging a PR implementing the new constants (I think there's one already up?) without deprecating the old ones immediately, and we can separately continue discussing, perhaps on an issue, when to deprecate the old variants. |
One concern with immediate deprecation is that people supporting multiple versions of Rust with the same source would be forced to either disable deprecation warnings or immediately switch to the new version which wouldn't compile on older versions (since it's not there yet). Both of those don't seem like a good migration path. |
I would be in favor of a PR implementing the new constants without marking the old constants |
Yes. I prepared and submitted rust-lang/rust#68325 with just this content. |
Am I correct in drawing the following conclusions from the deprecation thread above:
If this seems agreeable, then I submit that this RFC could be approved and merged at any time. A timeframe for deprecation, however long it might be or whatever form it might take, can easily be left to the tracking issue. |
It is my opinion that (presuming that was the unresolved issue), this RFC is ready for merging, per your comment's summary of the deprecation question. |
I concur; we have accepted the RFC, we can add the associated constants now, and we loosely plan to deprecate but will negotiate the details later. Personally I hold out some hope that we can figure out a way to make std::i32 etc be a reexport of the type i32 instead of a module, at which point there is no longer anything to deprecate. |
This RFC was approved! Please use the tracking issue for further discussion. Thanks! |
…-step1, r=LukasKalbertodt Move numeric consts to associated consts step1 A subset of #67913. Implements the first step of RFC rust-lang/rfcs#2700 This PR adds the new constants as unstable constants and defines the old ones in terms of the new ones. Then fix a tiny bit of code that started having naming collisions because of the new assoc consts. Removed a test that did not seem relevant any longer. Since doing just `u8::MIN` should now indeed be valid.
Stabilize assoc_int_consts associated int/float constants The next step in RFC rust-lang/rfcs#2700 (tracking issue #68490). Stabilizing the associated constants that were added in #68325. * Stabilize all constants under the `assoc_int_consts` feature flag. * Update documentation on old constants to say they are soft-deprecated and the new ones should be preferred. * Update documentation examples to use new constants. * Remove `uint_macro` and use `int_macro` for all integer types since the macros were identical anyway. r? @LukasKalbertodt
…, r=dtolnay Migrate to numeric associated consts The deprecation PR is rust-lang#72885 cc rust-lang#68490 cc rust-lang/rfcs#2700
…, r=dtolnay Migrate to numeric associated consts The deprecation PR is rust-lang#72885 cc rust-lang#68490 cc rust-lang/rfcs#2700
…, r=dtolnay Migrate to numeric associated consts The deprecation PR is rust-lang#72885 cc rust-lang#68490 cc rust-lang/rfcs#2700
Migrate to numeric associated consts The deprecation PR is #72885 cc #68490 cc rust-lang/rfcs#2700
Add the relevant associated constants to the numeric types in the standard library, and consider a timeline for the deprecation of the corresponding (and originally intended to be temporary) primitive numeric modules and associated functions.
Rendered