Skip to content

Commit 7a3700c

Browse files
committed
Auto merge of #68952 - faern:stabilize-assoc-int-consts, r=dtolnay
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
2 parents 4d71c16 + b2dc618 commit 7a3700c

22 files changed

+263
-242
lines changed

src/libcore/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@
141141
#![feature(associated_type_bounds)]
142142
#![feature(const_type_id)]
143143
#![feature(const_caller_location)]
144-
#![feature(assoc_int_consts)]
145144
#![cfg_attr(not(bootstrap), feature(no_niche))] // rust-lang/rust#68303
146145

147146
#[prelude_import]
@@ -159,10 +158,6 @@ mod internal_macros;
159158
#[macro_use]
160159
mod int_macros;
161160

162-
#[path = "num/uint_macros.rs"]
163-
#[macro_use]
164-
mod uint_macros;
165-
166161
#[path = "num/i128.rs"]
167162
pub mod i128;
168163
#[path = "num/i16.rs"]

src/libcore/num/f32.rs

+33-27
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
//! *[See also the `f32` primitive type](../../std/primitive.f32.html).*
55
//!
66
//! Mathematically significant numbers are provided in the `consts` sub-module.
7+
//!
8+
//! Although using these constants won’t cause compilation warnings,
9+
//! new code should use the associated constants directly on the primitive type.
710
811
#![stable(feature = "rust1", since = "1.0.0")]
912

@@ -14,17 +17,21 @@ use crate::mem;
1417
use crate::num::FpCategory;
1518

1619
/// The radix or base of the internal representation of `f32`.
20+
/// Use [`f32::RADIX`](../../std/primitive.f32.html#associatedconstant.RADIX) instead.
1721
#[stable(feature = "rust1", since = "1.0.0")]
1822
pub const RADIX: u32 = f32::RADIX;
1923

2024
/// Number of significant digits in base 2.
25+
/// Use [`f32::MANTISSA_DIGITS`](../../std/primitive.f32.html#associatedconstant.MANTISSA_DIGITS) instead.
2126
#[stable(feature = "rust1", since = "1.0.0")]
2227
pub const MANTISSA_DIGITS: u32 = f32::MANTISSA_DIGITS;
2328
/// Approximate number of significant digits in base 10.
29+
/// Use [`f32::DIGITS`](../../std/primitive.f32.html#associatedconstant.DIGITS) instead.
2430
#[stable(feature = "rust1", since = "1.0.0")]
2531
pub const DIGITS: u32 = f32::DIGITS;
2632

2733
/// [Machine epsilon] value for `f32`.
34+
/// Use [`f32::EPSILON`](../../std/primitive.f32.html#associatedconstant.EPSILON) instead.
2835
///
2936
/// This is the difference between `1.0` and the next larger representable number.
3037
///
@@ -33,36 +40,46 @@ pub const DIGITS: u32 = f32::DIGITS;
3340
pub const EPSILON: f32 = f32::EPSILON;
3441

3542
/// Smallest finite `f32` value.
43+
/// Use [`f32::MIN`](../../std/primitive.f32.html#associatedconstant.MIN) instead.
3644
#[stable(feature = "rust1", since = "1.0.0")]
3745
pub const MIN: f32 = f32::MIN;
3846
/// Smallest positive normal `f32` value.
47+
/// Use [`f32::MIN_POSITIVE`](../../std/primitive.f32.html#associatedconstant.MIN_POSITIVE) instead.
3948
#[stable(feature = "rust1", since = "1.0.0")]
4049
pub const MIN_POSITIVE: f32 = f32::MIN_POSITIVE;
4150
/// Largest finite `f32` value.
51+
/// Use [`f32::MAX`](../../std/primitive.f32.html#associatedconstant.MAX) instead.
4252
#[stable(feature = "rust1", since = "1.0.0")]
4353
pub const MAX: f32 = f32::MAX;
4454

4555
/// One greater than the minimum possible normal power of 2 exponent.
56+
/// Use [`f32::MIN_EXP`](../../std/primitive.f32.html#associatedconstant.MIN_EXP) instead.
4657
#[stable(feature = "rust1", since = "1.0.0")]
4758
pub const MIN_EXP: i32 = f32::MIN_EXP;
4859
/// Maximum possible power of 2 exponent.
60+
/// Use [`f32::MAX_EXP`](../../std/primitive.f32.html#associatedconstant.MAX_EXP) instead.
4961
#[stable(feature = "rust1", since = "1.0.0")]
5062
pub const MAX_EXP: i32 = f32::MAX_EXP;
5163

5264
/// Minimum possible normal power of 10 exponent.
65+
/// Use [`f32::MIN_10_EXP`](../../std/primitive.f32.html#associatedconstant.MIN_10_EXP) instead.
5366
#[stable(feature = "rust1", since = "1.0.0")]
5467
pub const MIN_10_EXP: i32 = f32::MIN_10_EXP;
5568
/// Maximum possible power of 10 exponent.
69+
/// Use [`f32::MAX_10_EXP`](../../std/primitive.f32.html#associatedconstant.MAX_10_EXP) instead.
5670
#[stable(feature = "rust1", since = "1.0.0")]
5771
pub const MAX_10_EXP: i32 = f32::MAX_10_EXP;
5872

5973
/// Not a Number (NaN).
74+
/// Use [`f32::NAN`](../../std/primitive.f32.html#associatedconstant.NAN) instead.
6075
#[stable(feature = "rust1", since = "1.0.0")]
6176
pub const NAN: f32 = f32::NAN;
6277
/// Infinity (∞).
78+
/// Use [`f32::INFINITY`](../../std/primitive.f32.html#associatedconstant.INFINITY) instead.
6379
#[stable(feature = "rust1", since = "1.0.0")]
6480
pub const INFINITY: f32 = f32::INFINITY;
6581
/// Negative infinity (−∞).
82+
/// Use [`f32::NEG_INFINITY`](../../std/primitive.f32.html#associatedconstant.NEG_INFINITY) instead.
6683
#[stable(feature = "rust1", since = "1.0.0")]
6784
pub const NEG_INFINITY: f32 = f32::NEG_INFINITY;
6885

@@ -154,64 +171,62 @@ pub mod consts {
154171
#[cfg(not(test))]
155172
impl f32 {
156173
/// The radix or base of the internal representation of `f32`.
157-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
174+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
158175
pub const RADIX: u32 = 2;
159176

160177
/// Number of significant digits in base 2.
161-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
178+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
162179
pub const MANTISSA_DIGITS: u32 = 24;
163180

164181
/// Approximate number of significant digits in base 10.
165-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
182+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
166183
pub const DIGITS: u32 = 6;
167184

168185
/// [Machine epsilon] value for `f32`.
169186
///
170187
/// This is the difference between `1.0` and the next larger representable number.
171188
///
172189
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
173-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
190+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
174191
pub const EPSILON: f32 = 1.19209290e-07_f32;
175192

176193
/// Smallest finite `f32` value.
177-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
194+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
178195
pub const MIN: f32 = -3.40282347e+38_f32;
179196
/// Smallest positive normal `f32` value.
180-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
197+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
181198
pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32;
182199
/// Largest finite `f32` value.
183-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
200+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
184201
pub const MAX: f32 = 3.40282347e+38_f32;
185202

186203
/// One greater than the minimum possible normal power of 2 exponent.
187-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
204+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
188205
pub const MIN_EXP: i32 = -125;
189206
/// Maximum possible power of 2 exponent.
190-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
207+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
191208
pub const MAX_EXP: i32 = 128;
192209

193210
/// Minimum possible normal power of 10 exponent.
194-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
211+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
195212
pub const MIN_10_EXP: i32 = -37;
196213
/// Maximum possible power of 10 exponent.
197-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
214+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
198215
pub const MAX_10_EXP: i32 = 38;
199216

200217
/// Not a Number (NaN).
201-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
218+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
202219
pub const NAN: f32 = 0.0_f32 / 0.0_f32;
203220
/// Infinity (∞).
204-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
221+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
205222
pub const INFINITY: f32 = 1.0_f32 / 0.0_f32;
206223
/// Negative infinity (-∞).
207-
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
224+
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
208225
pub const NEG_INFINITY: f32 = -1.0_f32 / 0.0_f32;
209226

210227
/// Returns `true` if this value is `NaN`.
211228
///
212229
/// ```
213-
/// use std::f32;
214-
///
215230
/// let nan = f32::NAN;
216231
/// let f = 7.0_f32;
217232
///
@@ -236,8 +251,6 @@ impl f32 {
236251
/// `false` otherwise.
237252
///
238253
/// ```
239-
/// use std::f32;
240-
///
241254
/// let f = 7.0f32;
242255
/// let inf = f32::INFINITY;
243256
/// let neg_inf = f32::NEG_INFINITY;
@@ -258,8 +271,6 @@ impl f32 {
258271
/// Returns `true` if this number is neither infinite nor `NaN`.
259272
///
260273
/// ```
261-
/// use std::f32;
262-
///
263274
/// let f = 7.0f32;
264275
/// let inf = f32::INFINITY;
265276
/// let neg_inf = f32::NEG_INFINITY;
@@ -283,8 +294,6 @@ impl f32 {
283294
/// [subnormal], or `NaN`.
284295
///
285296
/// ```
286-
/// use std::f32;
287-
///
288297
/// let min = f32::MIN_POSITIVE; // 1.17549435e-38f32
289298
/// let max = f32::MAX;
290299
/// let lower_than_min = 1.0e-40_f32;
@@ -312,7 +321,6 @@ impl f32 {
312321
///
313322
/// ```
314323
/// use std::num::FpCategory;
315-
/// use std::f32;
316324
///
317325
/// let num = 12.4_f32;
318326
/// let inf = f32::INFINITY;
@@ -372,8 +380,6 @@ impl f32 {
372380
/// Takes the reciprocal (inverse) of a number, `1/x`.
373381
///
374382
/// ```
375-
/// use std::f32;
376-
///
377383
/// let x = 2.0_f32;
378384
/// let abs_difference = (x.recip() - (1.0 / x)).abs();
379385
///
@@ -388,7 +394,7 @@ impl f32 {
388394
/// Converts radians to degrees.
389395
///
390396
/// ```
391-
/// use std::f32::{self, consts};
397+
/// use std::f32::consts;
392398
///
393399
/// let angle = consts::PI;
394400
///
@@ -407,7 +413,7 @@ impl f32 {
407413
/// Converts degrees to radians.
408414
///
409415
/// ```
410-
/// use std::f32::{self, consts};
416+
/// use std::f32::consts;
411417
///
412418
/// let angle = 180.0f32;
413419
///

0 commit comments

Comments
 (0)