Skip to content

Commit f28e387

Browse files
authored
Rollup merge of rust-lang#71366 - faern:use-assoc-int-consts3, r=dtolnay
Use assoc int consts3 Define module level int consts with associated constants instead of `min_value()` and `max_value()`. So the code become consistent with what the docs recommend etc. Seems natural. Also remove the last usages of the int module constants from this repo (except src/test/ directory which I have still not really done anything in). Some places were missed in the previous PRs because the code uses `crate::<IntTy>` to reach the constants. This is a continuation of rust-lang#70857 r? @dtolnay
2 parents 567e54f + 9af047f commit f28e387

File tree

16 files changed

+21
-28
lines changed

16 files changed

+21
-28
lines changed

src/libcore/iter/adapters/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::cmp;
22
use crate::fmt;
33
use crate::intrinsics;
44
use crate::ops::{Add, AddAssign, Try};
5-
use crate::usize;
65

76
use super::{from_fn, LoopState};
87
use super::{DoubleEndedIterator, ExactSizeIterator, FusedIterator, Iterator, TrustedLen};

src/libcore/iter/range.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::convert::TryFrom;
22
use crate::mem;
33
use crate::ops::{self, Add, Sub, Try};
4-
use crate::usize;
54

65
use super::{FusedIterator, TrustedLen};
76

src/libcore/iter/sources.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::fmt;
22
use crate::marker;
3-
use crate::usize;
43

54
use super::{FusedIterator, TrustedLen};
65

src/libcore/num/f32.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl f32 {
265265
#[stable(feature = "rust1", since = "1.0.0")]
266266
#[inline]
267267
pub fn is_infinite(self) -> bool {
268-
self.abs_private() == INFINITY
268+
self.abs_private() == Self::INFINITY
269269
}
270270

271271
/// Returns `true` if this number is neither infinite nor `NaN`.
@@ -287,7 +287,7 @@ impl f32 {
287287
pub fn is_finite(self) -> bool {
288288
// There's no need to handle NaN separately: if self is NaN,
289289
// the comparison is not true, exactly as desired.
290-
self.abs_private() < INFINITY
290+
self.abs_private() < Self::INFINITY
291291
}
292292

293293
/// Returns `true` if the number is neither zero, infinite,

src/libcore/num/f64.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl f64 {
264264
#[stable(feature = "rust1", since = "1.0.0")]
265265
#[inline]
266266
pub fn is_infinite(self) -> bool {
267-
self.abs_private() == INFINITY
267+
self.abs_private() == Self::INFINITY
268268
}
269269

270270
/// Returns `true` if this number is neither infinite nor `NaN`.
@@ -286,7 +286,7 @@ impl f64 {
286286
pub fn is_finite(self) -> bool {
287287
// There's no need to handle NaN separately: if self is NaN,
288288
// the comparison is not true, exactly as desired.
289-
self.abs_private() < INFINITY
289+
self.abs_private() < Self::INFINITY
290290
}
291291

292292
/// Returns `true` if the number is neither zero, infinite,

src/libcore/num/flt2dec/decoder.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::num::dec2flt::rawfp::RawFloat;
44
use crate::num::FpCategory;
5-
use crate::{f32, f64};
65

76
/// Decoded unsigned finite value, such that:
87
///

src/libcore/num/flt2dec/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ functions.
123123
)]
124124

125125
pub use self::decoder::{decode, DecodableFloat, Decoded, FullDecoded};
126-
use crate::i16;
127126

128127
pub mod decoder;
129128
pub mod estimator;

src/libcore/num/int_macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ macro_rules! int_module {
1414
concat!("The smallest value that can be represented by this integer type.
1515
Use [`", stringify!($T), "::MIN", "`](../../std/primitive.", stringify!($T), ".html#associatedconstant.MIN) instead."),
1616
#[$attr]
17-
pub const MIN: $T = $T::min_value();
17+
pub const MIN: $T = $T::MIN;
1818
}
1919

2020
doc_comment! {
2121
concat!("The largest value that can be represented by this integer type.
2222
Use [`", stringify!($T), "::MAX", "`](../../std/primitive.", stringify!($T), ".html#associatedconstant.MAX) instead."),
2323
#[$attr]
24-
pub const MAX: $T = $T::max_value();
24+
pub const MAX: $T = $T::MAX;
2525
}
2626
)
2727
}

src/libcore/slice/memchr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn repeat_byte(b: u8) -> usize {
3434
#[cfg(not(target_pointer_width = "16"))]
3535
#[inline]
3636
fn repeat_byte(b: u8) -> usize {
37-
(b as usize) * (crate::usize::MAX / 255)
37+
(b as usize) * (usize::MAX / 255)
3838
}
3939

4040
/// Returns the first index matching the byte `x` in `text`.

src/libcore/slice/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use crate::cmp;
2828
use crate::cmp::Ordering::{self, Equal, Greater, Less};
2929
use crate::fmt;
3030
use crate::intrinsics::{assume, exact_div, is_aligned_and_not_null, unchecked_sub};
31-
use crate::isize;
3231
use crate::iter::*;
3332
use crate::marker::{self, Copy, Send, Sized, Sync};
3433
use crate::mem;

src/libcore/str/pattern.rs

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
use crate::cmp;
4747
use crate::fmt;
4848
use crate::slice::memchr;
49-
use crate::usize;
5049

5150
// Pattern
5251

src/libcore/time.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
//! assert_eq!(Duration::new(5, 0), Duration::from_secs(5));
1313
//! ```
1414
15+
use crate::fmt;
1516
use crate::iter::Sum;
1617
use crate::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
17-
use crate::{fmt, u64};
1818

1919
const NANOS_PER_SEC: u32 = 1_000_000_000;
2020
const NANOS_PER_MILLI: u32 = 1_000_000;

src/libstd/f32.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl f32 {
171171
#[stable(feature = "rust1", since = "1.0.0")]
172172
#[inline]
173173
pub fn signum(self) -> f32 {
174-
if self.is_nan() { NAN } else { 1.0_f32.copysign(self) }
174+
if self.is_nan() { Self::NAN } else { 1.0_f32.copysign(self) }
175175
}
176176

177177
/// Returns a number composed of the magnitude of `self` and the sign of
@@ -832,8 +832,8 @@ impl f32 {
832832
#[stable(feature = "rust1", since = "1.0.0")]
833833
#[inline]
834834
pub fn asinh(self) -> f32 {
835-
if self == NEG_INFINITY {
836-
NEG_INFINITY
835+
if self == Self::NEG_INFINITY {
836+
Self::NEG_INFINITY
837837
} else {
838838
(self + ((self * self) + 1.0).sqrt()).ln().copysign(self)
839839
}
@@ -855,7 +855,7 @@ impl f32 {
855855
#[stable(feature = "rust1", since = "1.0.0")]
856856
#[inline]
857857
pub fn acosh(self) -> f32 {
858-
if self < 1.0 { crate::f32::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
858+
if self < 1.0 { Self::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
859859
}
860860

861861
/// Inverse hyperbolic tangent function.

src/libstd/f64.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl f64 {
171171
#[stable(feature = "rust1", since = "1.0.0")]
172172
#[inline]
173173
pub fn signum(self) -> f64 {
174-
if self.is_nan() { NAN } else { 1.0_f64.copysign(self) }
174+
if self.is_nan() { Self::NAN } else { 1.0_f64.copysign(self) }
175175
}
176176

177177
/// Returns a number composed of the magnitude of `self` and the sign of
@@ -834,8 +834,8 @@ impl f64 {
834834
#[stable(feature = "rust1", since = "1.0.0")]
835835
#[inline]
836836
pub fn asinh(self) -> f64 {
837-
if self == NEG_INFINITY {
838-
NEG_INFINITY
837+
if self == Self::NEG_INFINITY {
838+
Self::NEG_INFINITY
839839
} else {
840840
(self + ((self * self) + 1.0).sqrt()).ln().copysign(self)
841841
}
@@ -857,7 +857,7 @@ impl f64 {
857857
#[stable(feature = "rust1", since = "1.0.0")]
858858
#[inline]
859859
pub fn acosh(self) -> f64 {
860-
if self < 1.0 { NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
860+
if self < 1.0 { Self::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
861861
}
862862

863863
/// Inverse hyperbolic tangent function.
@@ -926,16 +926,16 @@ impl f64 {
926926
if self > 0.0 {
927927
log_fn(self)
928928
} else if self == 0.0 {
929-
NEG_INFINITY // log(0) = -Inf
929+
Self::NEG_INFINITY // log(0) = -Inf
930930
} else {
931-
NAN // log(-n) = NaN
931+
Self::NAN // log(-n) = NaN
932932
}
933933
} else if self.is_nan() {
934934
self // log(NaN) = NaN
935935
} else if self > 0.0 {
936936
self // log(Inf) = Inf
937937
} else {
938-
NAN // log(-Inf) = NaN
938+
Self::NAN // log(-Inf) = NaN
939939
}
940940
}
941941
}

src/libstd/thread/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ impl ThreadId {
10621062

10631063
// If we somehow use up all our bits, panic so that we're not
10641064
// covering up subtle bugs of IDs being reused.
1065-
if COUNTER == crate::u64::MAX {
1065+
if COUNTER == u64::MAX {
10661066
panic!("failed to generate unique thread ID: bitspace exhausted");
10671067
}
10681068

src/test/rustdoc/show-const-contents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub const MY_TYPE_WITH_STR: MyTypeWithStr = MyTypeWithStr("show this");
5151
// @has show_const_contents/constant.PI.html '; // 3.14159274f32'
5252
pub use std::f32::consts::PI;
5353

54-
// @has show_const_contents/constant.MAX.html '= i32::max_value(); // 2_147_483_647i32'
54+
// @has show_const_contents/constant.MAX.html '= i32::MAX; // 2_147_483_647i32'
5555
pub use std::i32::MAX;
5656

5757
macro_rules! int_module {

0 commit comments

Comments
 (0)