-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
This is a tracking issue for the RFC 2700 (rust-lang/rfcs#2700): "Deprecate stdlib modules dedicated to numeric constants and move those constants to associated consts".
Steps:
- Add new constants (see Move numeric consts to associated consts step1 #68325)Stabilize new constants (see instructions on rustc-guide)Update test suite to use new constants (Update tests to remove old numeric constants #78380)Fix error messages using old symbols (Prefer new associated numeric consts in float error messages #78382)Support for indeterminate deprecation dates (Allow
deprecated_in_future
lint to specify an indeterminate future deprecation date #78381)Deprecate-in-future the old itemsFully deprecate the old itemsAdjust documentation (see instructions on rustc-guide)To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Unresolved questions:
- [Resolved: Yes] Should the old items be deprecated? See the RFC thread as well as "unresolved questions":
How long should we go before issuing a deprecation warning? At the extreme end of the scale we could wait until the next edition of Rust is released, and have the legacy items only issue deprecation warnings when opting in to the new edition; this would limit disruption only to people opting in to a new edition (and, being merely an trivially-addressed deprecation, would constitute far less of a disruption than any ordinary edition-related change; any impact of the deprecation would be mere noise in light of the broader edition-related impacts). However long it takes, it is the opinion of the author that deprecation should happen eventually, as we should not give the impression that it is the ideal state of things that there should exist three ways of finding the maximum value of an integer type; we expect experienced users to intuitively reach for the new way proposed in this RFC as the "natural" way these constants ought to be implemented, but for the sake of new users it would be a pedagogical wart to allow all three to exist without explicitly calling out the preferred one.
[Resolved: No] Should constants fromstd::{f32, f64}::consts
also be made associated consts? From the alternative question of the RFC:Unlike the twelve integral modules, the two floating-point modules would not themselves be entirely deprecated by the changes proposed here. This is because the
std::f32
andstd::f64
modules each contain aconsts
submodule, in which reside constants of a more mathematical bent (the sort of things other languages might put in astd::math
module).It is the author's opinion that special treatment for such "math-oriented constants" (as opposed to the "machine-oriented constants" addressed by this RFC) is not particularly precedented; e.g. this separation is not consistent with the existing set of associated functions implemented on
f32
andf64
, 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
). However, although earlier versions of this RFC proposed deprecatingstd::{f32, f64}::consts
(and therebystd::{f32, f64}
as well), the current version does not do so, as this was met with mild resistance (and, in any case, the greatest gains from this RFC will be its impact on the integral modules).Ultimately, there is no reason that such a change could not be left to a future RFC if desired. However, one alternative design would be to turn all the constants in
{f32, f64}
into associated consts as well, which would leave no more modules in the standard library that shadow primitive types. A different alternative would be to restrict this RFC only to the integral modules, leaving f32 and f64 for a future RFC, since the integral modules are the most important aspect of this RFC and it would be a shame for them to get bogged down by the unrelated concerns of the floating-point modules.To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Activity
agausmann commentedon Jan 23, 2020
faern commentedon Feb 5, 2020
I have implemented the stabilization and documentation changes needed to show people which constant is the preferred one now. I will submit this as a PR in a few days when the unstable version has been out for a bit over a week.
You can find the code here: https://github.com/rust-lang/rust/compare/master...faern:stabilize-assoc-int-consts?expand=1
What parts of it I don't think will be controversial at all:
Other changes that possibly might create some discussion:
min_value
,max_value
methods to the very bottom of the integer impl block, so they are not taking up the best spots in the documentation, but is rather moved away a bit. TheMIN
/MAX
constants took their place. They can still of course easily be found, but they are not at the very top.I opted for doing what
Error::description()
did with the documentation. Saying something like this:I added soft deprecation notices to:
core
andstd
modules for all integer and float typesMIN
/MAX
constants in the integer modules.min_value
/max_value
methods on the integer types.faern commentedon Feb 8, 2020
The code/docs were changed a bit after I wrote that last comment just above. But the stabilization PR is live now.
Auto merge of #68952 - faern:stabilize-assoc-int-consts, r=dtolnay
faern commentedon Jun 9, 2020
One thing that remains is to improve the compiler error that mentions the
MIN
andMAX
constants. Try this code on nightly:It gives the following error:
Now when the associated constants are the preferred ones the error should be
Rollup merge of rust-lang#72906 - lzutao:migrate-numeric-assoc-consts…
47 remaining items