Skip to content

Commit 9b22fdc

Browse files
authored
Rollup merge of #69860 - faern:use-assoc-int-consts, r=dtolnay
Use associated numeric consts in documentation Now when the associated constants on int/float types are stabilized and the recommended way of accessing said constants (#68952). We can start using it in this repository, and recommend it via documentation example code. This PR is the reincarnation of #67913 minus the actual adding + stabilization of said constants. (EDIT: Now it's only changing the documentation. So users will see the new consts, but we don't yet update the internal code) Because of how fast bit rot happens to PRs that touch this many files, it does not try to replace 100% of the old usage of the constants in the entire repo, but a good chunk of them.
2 parents f6fe99c + c831265 commit 9b22fdc

File tree

18 files changed

+34
-36
lines changed

18 files changed

+34
-36
lines changed

src/liballoc/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl<T> [T] {
432432
///
433433
/// ```should_panic
434434
/// // this will panic at runtime
435-
/// b"0123456789abcdef".repeat(usize::max_value());
435+
/// b"0123456789abcdef".repeat(usize::MAX);
436436
/// ```
437437
#[stable(feature = "repeat_generic_slice", since = "1.40.0")]
438438
pub fn repeat(&self, n: usize) -> Vec<T>

src/liballoc/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl str {
499499
///
500500
/// ```should_panic
501501
/// // this will panic at runtime
502-
/// "0123456789abcdef".repeat(usize::max_value());
502+
/// "0123456789abcdef".repeat(usize::MAX);
503503
/// ```
504504
#[stable(feature = "repeat_str", since = "1.16.0")]
505505
pub fn repeat(&self, n: usize) -> String {

src/libcore/cmp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
817817
/// When comparison is impossible:
818818
///
819819
/// ```
820-
/// let result = std::f64::NAN.partial_cmp(&1.0);
820+
/// let result = f64::NAN.partial_cmp(&1.0);
821821
/// assert_eq!(result, None);
822822
/// ```
823823
#[must_use]

src/libcore/fmt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ pub trait LowerHex {
852852
/// }
853853
/// }
854854
///
855-
/// let l = Length(i32::max_value());
855+
/// let l = Length(i32::MAX);
856856
///
857857
/// assert_eq!(format!("l as hex is: {:X}", l), "l as hex is: 7FFFFFFF");
858858
///

src/libcore/hint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::intrinsics;
4343
///
4444
/// assert_eq!(div_1(7, 0), 7);
4545
/// assert_eq!(div_1(9, 1), 4);
46-
/// assert_eq!(div_1(11, std::u32::MAX), 0);
46+
/// assert_eq!(div_1(11, u32::MAX), 0);
4747
/// ```
4848
#[inline]
4949
#[stable(feature = "unreachable", since = "1.27.0")]

src/libcore/intrinsics.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1739,19 +1739,19 @@ extern "rust-intrinsic" {
17391739
pub fn mul_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
17401740

17411741
/// Performs an exact division, resulting in undefined behavior where
1742-
/// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
1742+
/// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
17431743
pub fn exact_div<T: Copy>(x: T, y: T) -> T;
17441744

17451745
/// Performs an unchecked division, resulting in undefined behavior
1746-
/// where y = 0 or x = `T::min_value()` and y = -1
1746+
/// where y = 0 or x = `T::MIN` and y = -1
17471747
///
17481748
/// The stabilized versions of this intrinsic are available on the integer
17491749
/// primitives via the `checked_div` method. For example,
17501750
/// [`std::u32::checked_div`](../../std/primitive.u32.html#method.checked_div)
17511751
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
17521752
pub fn unchecked_div<T: Copy>(x: T, y: T) -> T;
17531753
/// Returns the remainder of an unchecked division, resulting in
1754-
/// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
1754+
/// undefined behavior where y = 0 or x = `T::MIN` and y = -1
17551755
///
17561756
/// The stabilized versions of this intrinsic are available on the integer
17571757
/// primitives via the `checked_rem` method. For example,
@@ -1777,17 +1777,17 @@ extern "rust-intrinsic" {
17771777
pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T;
17781778

17791779
/// Returns the result of an unchecked addition, resulting in
1780-
/// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`.
1780+
/// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
17811781
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
17821782
pub fn unchecked_add<T: Copy>(x: T, y: T) -> T;
17831783

17841784
/// Returns the result of an unchecked subtraction, resulting in
1785-
/// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`.
1785+
/// undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`.
17861786
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
17871787
pub fn unchecked_sub<T: Copy>(x: T, y: T) -> T;
17881788

17891789
/// Returns the result of an unchecked multiplication, resulting in
1790-
/// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`.
1790+
/// undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`.
17911791
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
17921792
pub fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
17931793

src/libcore/iter/traits/iterator.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub trait Iterator {
198198
/// // and the maximum possible lower bound
199199
/// let iter = 0..;
200200
///
201-
/// assert_eq!((usize::max_value(), None), iter.size_hint());
201+
/// assert_eq!((usize::MAX, None), iter.size_hint());
202202
/// ```
203203
#[inline]
204204
#[stable(feature = "rust1", since = "1.0.0")]
@@ -2920,7 +2920,7 @@ pub trait Iterator {
29202920
/// assert_eq!([1.].iter().partial_cmp([1., 2.].iter()), Some(Ordering::Less));
29212921
/// assert_eq!([1., 2.].iter().partial_cmp([1.].iter()), Some(Ordering::Greater));
29222922
///
2923-
/// assert_eq!([std::f64::NAN].iter().partial_cmp([1.].iter()), None);
2923+
/// assert_eq!([f64::NAN].iter().partial_cmp([1.].iter()), None);
29242924
/// ```
29252925
#[stable(feature = "iter_order", since = "1.5.0")]
29262926
fn partial_cmp<I>(self, other: I) -> Option<Ordering>
@@ -3170,7 +3170,7 @@ pub trait Iterator {
31703170
/// assert!(![1, 3, 2, 4].iter().is_sorted());
31713171
/// assert!([0].iter().is_sorted());
31723172
/// assert!(std::iter::empty::<i32>().is_sorted());
3173-
/// assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted());
3173+
/// assert!(![0.0, 1.0, f32::NAN].iter().is_sorted());
31743174
/// ```
31753175
#[inline]
31763176
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
@@ -3197,7 +3197,7 @@ pub trait Iterator {
31973197
/// assert!(![1, 3, 2, 4].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
31983198
/// assert!([0].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
31993199
/// assert!(std::iter::empty::<i32>().is_sorted_by(|a, b| a.partial_cmp(b)));
3200-
/// assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
3200+
/// assert!(![0.0, 1.0, f32::NAN].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
32013201
/// ```
32023202
///
32033203
/// [`is_sorted`]: trait.Iterator.html#method.is_sorted

src/libcore/num/f32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl f32 {
470470
///
471471
/// let value = -128.9_f32;
472472
/// let rounded = unsafe { value.to_int_unchecked::<i8>() };
473-
/// assert_eq!(rounded, std::i8::MIN);
473+
/// assert_eq!(rounded, i8::MIN);
474474
/// ```
475475
///
476476
/// # Safety

src/libcore/num/f64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl f64 {
484484
///
485485
/// let value = -128.9_f32;
486486
/// let rounded = unsafe { value.to_int_unchecked::<i8>() };
487-
/// assert_eq!(rounded, std::i8::MIN);
487+
/// assert_eq!(rounded, i8::MIN);
488488
/// ```
489489
///
490490
/// # Safety

src/libcore/num/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ NonZeroI8 NonZeroI16 NonZeroI32 NonZeroI64 NonZeroI128 NonZeroIsize }
174174
/// let zero = Wrapping(0u32);
175175
/// let one = Wrapping(1u32);
176176
///
177-
/// assert_eq!(std::u32::MAX, (zero - one).0);
177+
/// assert_eq!(u32::MAX, (zero - one).0);
178178
/// ```
179179
#[stable(feature = "rust1", since = "1.0.0")]
180180
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)]

src/libcore/ops/range.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,9 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
139139
/// ```
140140
/// #![feature(range_is_empty)]
141141
///
142-
/// use std::f32::NAN;
143142
/// assert!(!(3.0..5.0).is_empty());
144-
/// assert!( (3.0..NAN).is_empty());
145-
/// assert!( (NAN..5.0).is_empty());
143+
/// assert!( (3.0..f32::NAN).is_empty());
144+
/// assert!( (f32::NAN..5.0).is_empty());
146145
/// ```
147146
#[unstable(feature = "range_is_empty", reason = "recently added", issue = "48111")]
148147
pub fn is_empty(&self) -> bool {
@@ -496,10 +495,9 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
496495
/// ```
497496
/// #![feature(range_is_empty)]
498497
///
499-
/// use std::f32::NAN;
500498
/// assert!(!(3.0..=5.0).is_empty());
501-
/// assert!( (3.0..=NAN).is_empty());
502-
/// assert!( (NAN..=5.0).is_empty());
499+
/// assert!( (3.0..=f32::NAN).is_empty());
500+
/// assert!( (f32::NAN..=5.0).is_empty());
503501
/// ```
504502
///
505503
/// This method returns `true` after iteration has finished:

src/libcore/ptr/const_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,8 @@ impl<T: ?Sized> *const T {
659659
/// `align`.
660660
///
661661
/// If it is not possible to align the pointer, the implementation returns
662-
/// `usize::max_value()`. It is permissible for the implementation to *always*
663-
/// return `usize::max_value()`. Only your algorithm's performance can depend
662+
/// `usize::MAX`. It is permissible for the implementation to *always*
663+
/// return `usize::MAX`. Only your algorithm's performance can depend
664664
/// on getting a usable offset here, not its correctness.
665665
///
666666
/// The offset is expressed in number of `T` elements, and not bytes. The value returned can be

src/libcore/ptr/mut_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,8 @@ impl<T: ?Sized> *mut T {
847847
/// `align`.
848848
///
849849
/// If it is not possible to align the pointer, the implementation returns
850-
/// `usize::max_value()`. It is permissible for the implementation to *always*
851-
/// return `usize::max_value()`. Only your algorithm's performance can depend
850+
/// `usize::MAX`. It is permissible for the implementation to *always*
851+
/// return `usize::MAX`. Only your algorithm's performance can depend
852852
/// on getting a usable offset here, not its correctness.
853853
///
854854
/// The offset is expressed in number of `T` elements, and not bytes. The value returned can be

src/libcore/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,7 @@ impl<T> [T] {
25882588
/// assert!(![1, 3, 2, 4].is_sorted());
25892589
/// assert!([0].is_sorted());
25902590
/// assert!(empty.is_sorted());
2591-
/// assert!(![0.0, 1.0, std::f32::NAN].is_sorted());
2591+
/// assert!(![0.0, 1.0, f32::NAN].is_sorted());
25922592
/// ```
25932593
#[inline]
25942594
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]

src/libcore/time.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl Duration {
389389
/// use std::time::Duration;
390390
///
391391
/// assert_eq!(Duration::new(0, 0).checked_add(Duration::new(0, 1)), Some(Duration::new(0, 1)));
392-
/// assert_eq!(Duration::new(1, 0).checked_add(Duration::new(std::u64::MAX, 0)), None);
392+
/// assert_eq!(Duration::new(1, 0).checked_add(Duration::new(u64::MAX, 0)), None);
393393
/// ```
394394
#[stable(feature = "duration_checked_ops", since = "1.16.0")]
395395
#[inline]
@@ -460,7 +460,7 @@ impl Duration {
460460
/// use std::time::Duration;
461461
///
462462
/// assert_eq!(Duration::new(0, 500_000_001).checked_mul(2), Some(Duration::new(1, 2)));
463-
/// assert_eq!(Duration::new(std::u64::MAX - 1, 0).checked_mul(2), None);
463+
/// assert_eq!(Duration::new(u64::MAX - 1, 0).checked_mul(2), None);
464464
/// ```
465465
#[stable(feature = "duration_checked_ops", since = "1.16.0")]
466466
#[inline]

src/librustc_target/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ pub struct Scalar {
577577
pub value: Primitive,
578578

579579
/// Inclusive wrap-around range of valid values, that is, if
580-
/// start > end, it represents `start..=max_value()`,
580+
/// start > end, it represents `start..=MAX`,
581581
/// followed by `0..=end`.
582582
///
583583
/// That is, for an i8 primitive, a range of `254..=2` means following

src/libstd/f32.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl f32 {
284284
/// assert_eq!(a.rem_euclid(-b), 3.0);
285285
/// assert_eq!((-a).rem_euclid(-b), 1.0);
286286
/// // limitation due to round-off error
287-
/// assert!((-std::f32::EPSILON).rem_euclid(3.0) != 0.0);
287+
/// assert!((-f32::EPSILON).rem_euclid(3.0) != 0.0);
288288
/// ```
289289
#[must_use = "method returns a new number and does not mutate the original value"]
290290
#[inline]
@@ -962,7 +962,7 @@ impl f32 {
962962
/// assert!((-3.0f32).clamp(-2.0, 1.0) == -2.0);
963963
/// assert!((0.0f32).clamp(-2.0, 1.0) == 0.0);
964964
/// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0);
965-
/// assert!((std::f32::NAN).clamp(-2.0, 1.0).is_nan());
965+
/// assert!((f32::NAN).clamp(-2.0, 1.0).is_nan());
966966
/// ```
967967
#[must_use = "method returns a new number and does not mutate the original value"]
968968
#[unstable(feature = "clamp", issue = "44095")]

src/libstd/f64.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl f64 {
280280
/// assert_eq!(a.rem_euclid(-b), 3.0);
281281
/// assert_eq!((-a).rem_euclid(-b), 1.0);
282282
/// // limitation due to round-off error
283-
/// assert!((-std::f64::EPSILON).rem_euclid(3.0) != 0.0);
283+
/// assert!((-f64::EPSILON).rem_euclid(3.0) != 0.0);
284284
/// ```
285285
#[must_use = "method returns a new number and does not mutate the original value"]
286286
#[inline]
@@ -928,7 +928,7 @@ impl f64 {
928928
/// assert!((-3.0f64).clamp(-2.0, 1.0) == -2.0);
929929
/// assert!((0.0f64).clamp(-2.0, 1.0) == 0.0);
930930
/// assert!((2.0f64).clamp(-2.0, 1.0) == 1.0);
931-
/// assert!((std::f64::NAN).clamp(-2.0, 1.0).is_nan());
931+
/// assert!((f64::NAN).clamp(-2.0, 1.0).is_nan());
932932
/// ```
933933
#[must_use = "method returns a new number and does not mutate the original value"]
934934
#[unstable(feature = "clamp", issue = "44095")]

0 commit comments

Comments
 (0)