Skip to content

Commit 7c78a5f

Browse files
committed
Auto merge of #73276 - Dylan-DPC:rollup-hfd81qw, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #72906 (Migrate to numeric associated consts) - #73178 (expand: More precise locations for expansion-time lints) - #73225 (Allow inference regions when relating consts) - #73236 (Clean up E0666 explanation) - #73273 (Fix Zulip pings) Failed merges: r? @ghost
2 parents 5949391 + 77ede48 commit 7c78a5f

File tree

119 files changed

+662
-568
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+662
-568
lines changed

src/liballoc/rc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ trait RcBoxPtr<T: ?Sized> {
20342034
// The reference count will never be zero when this is called;
20352035
// nevertheless, we insert an abort here to hint LLVM at
20362036
// an otherwise missed optimization.
2037-
if strong == 0 || strong == usize::max_value() {
2037+
if strong == 0 || strong == usize::MAX {
20382038
abort();
20392039
}
20402040
self.inner().strong.set(strong + 1);
@@ -2058,7 +2058,7 @@ trait RcBoxPtr<T: ?Sized> {
20582058
// The reference count will never be zero when this is called;
20592059
// nevertheless, we insert an abort here to hint LLVM at
20602060
// an otherwise missed optimization.
2061-
if weak == 0 || weak == usize::max_value() {
2061+
if weak == 0 || weak == usize::MAX {
20622062
abort();
20632063
}
20642064
self.inner().weak.set(weak + 1);

src/liballoc/rc/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,14 @@ fn test_from_vec() {
407407
fn test_downcast() {
408408
use std::any::Any;
409409

410-
let r1: Rc<dyn Any> = Rc::new(i32::max_value());
410+
let r1: Rc<dyn Any> = Rc::new(i32::MAX);
411411
let r2: Rc<dyn Any> = Rc::new("abc");
412412

413413
assert!(r1.clone().downcast::<u32>().is_err());
414414

415415
let r1i32 = r1.downcast::<i32>();
416416
assert!(r1i32.is_ok());
417-
assert_eq!(r1i32.unwrap(), Rc::new(i32::max_value()));
417+
assert_eq!(r1i32.unwrap(), Rc::new(i32::MAX));
418418

419419
assert!(r2.clone().downcast::<i32>().is_err());
420420

src/liballoc/sync/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,14 @@ fn test_from_vec() {
465465
fn test_downcast() {
466466
use std::any::Any;
467467

468-
let r1: Arc<dyn Any + Send + Sync> = Arc::new(i32::max_value());
468+
let r1: Arc<dyn Any + Send + Sync> = Arc::new(i32::MAX);
469469
let r2: Arc<dyn Any + Send + Sync> = Arc::new("abc");
470470

471471
assert!(r1.clone().downcast::<u32>().is_err());
472472

473473
let r1i32 = r1.downcast::<i32>();
474474
assert!(r1i32.is_ok());
475-
assert_eq!(r1i32.unwrap(), Arc::new(i32::max_value()));
475+
assert_eq!(r1i32.unwrap(), Arc::new(i32::MAX));
476476

477477
assert!(r2.clone().downcast::<i32>().is_err());
478478

src/liballoc/tests/str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,13 @@ mod slice_index {
566566
data: "hello";
567567
// note: using 0 specifically ensures that the result of overflowing is 0..0,
568568
// so that `get` doesn't simply return None for the wrong reason.
569-
bad: data[0..=usize::max_value()];
569+
bad: data[0..=usize::MAX];
570570
message: "maximum usize";
571571
}
572572

573573
in mod rangetoinclusive {
574574
data: "hello";
575-
bad: data[..=usize::max_value()];
575+
bad: data[..=usize::MAX];
576576
message: "maximum usize";
577577
}
578578
}

src/liballoc/tests/vec.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn test_reserve() {
6868

6969
#[test]
7070
fn test_zst_capacity() {
71-
assert_eq!(Vec::<()>::new().capacity(), usize::max_value());
71+
assert_eq!(Vec::<()>::new().capacity(), usize::MAX);
7272
}
7373

7474
#[test]
@@ -563,19 +563,19 @@ fn test_drain_inclusive_range() {
563563

564564
#[test]
565565
fn test_drain_max_vec_size() {
566-
let mut v = Vec::<()>::with_capacity(usize::max_value());
566+
let mut v = Vec::<()>::with_capacity(usize::MAX);
567567
unsafe {
568-
v.set_len(usize::max_value());
568+
v.set_len(usize::MAX);
569569
}
570-
for _ in v.drain(usize::max_value() - 1..) {}
571-
assert_eq!(v.len(), usize::max_value() - 1);
570+
for _ in v.drain(usize::MAX - 1..) {}
571+
assert_eq!(v.len(), usize::MAX - 1);
572572

573-
let mut v = Vec::<()>::with_capacity(usize::max_value());
573+
let mut v = Vec::<()>::with_capacity(usize::MAX);
574574
unsafe {
575-
v.set_len(usize::max_value());
575+
v.set_len(usize::MAX);
576576
}
577-
for _ in v.drain(usize::max_value() - 1..=usize::max_value() - 1) {}
578-
assert_eq!(v.len(), usize::max_value() - 1);
577+
for _ in v.drain(usize::MAX - 1..=usize::MAX - 1) {}
578+
assert_eq!(v.len(), usize::MAX - 1);
579579
}
580580

581581
#[test]

src/libcore/cell.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1163,16 +1163,16 @@ impl<'b> BorrowRef<'b> {
11631163
// Incrementing borrow can result in a non-reading value (<= 0) in these cases:
11641164
// 1. It was < 0, i.e. there are writing borrows, so we can't allow a read borrow
11651165
// due to Rust's reference aliasing rules
1166-
// 2. It was isize::max_value() (the max amount of reading borrows) and it overflowed
1167-
// into isize::min_value() (the max amount of writing borrows) so we can't allow
1166+
// 2. It was isize::MAX (the max amount of reading borrows) and it overflowed
1167+
// into isize::MIN (the max amount of writing borrows) so we can't allow
11681168
// an additional read borrow because isize can't represent so many read borrows
11691169
// (this can only happen if you mem::forget more than a small constant amount of
11701170
// `Ref`s, which is not good practice)
11711171
None
11721172
} else {
11731173
// Incrementing borrow can result in a reading value (> 0) in these cases:
11741174
// 1. It was = 0, i.e. it wasn't borrowed, and we are taking the first read borrow
1175-
// 2. It was > 0 and < isize::max_value(), i.e. there were read borrows, and isize
1175+
// 2. It was > 0 and < isize::MAX, i.e. there were read borrows, and isize
11761176
// is large enough to represent having one more read borrow
11771177
borrow.set(b);
11781178
Some(BorrowRef { borrow })
@@ -1198,7 +1198,7 @@ impl Clone for BorrowRef<'_> {
11981198
debug_assert!(is_reading(borrow));
11991199
// Prevent the borrow counter from overflowing into
12001200
// a writing borrow.
1201-
assert!(borrow != isize::max_value());
1201+
assert!(borrow != isize::MAX);
12021202
self.borrow.set(borrow + 1);
12031203
BorrowRef { borrow: self.borrow }
12041204
}
@@ -1489,7 +1489,7 @@ impl<'b> BorrowRefMut<'b> {
14891489
let borrow = self.borrow.get();
14901490
debug_assert!(is_writing(borrow));
14911491
// Prevent the borrow counter from underflowing.
1492-
assert!(borrow != isize::min_value());
1492+
assert!(borrow != isize::MIN);
14931493
self.borrow.set(borrow - 1);
14941494
BorrowRefMut { borrow: self.borrow }
14951495
}

src/libcore/convert/num.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ macro_rules! try_from_upper_bounded {
217217
/// is outside of the range of the target type.
218218
#[inline]
219219
fn try_from(u: $source) -> Result<Self, Self::Error> {
220-
if u > (Self::max_value() as $source) {
220+
if u > (Self::MAX as $source) {
221221
Err(TryFromIntError(()))
222222
} else {
223223
Ok(u as Self)
@@ -239,8 +239,8 @@ macro_rules! try_from_both_bounded {
239239
/// is outside of the range of the target type.
240240
#[inline]
241241
fn try_from(u: $source) -> Result<Self, Self::Error> {
242-
let min = Self::min_value() as $source;
243-
let max = Self::max_value() as $source;
242+
let min = Self::MIN as $source;
243+
let max = Self::MAX as $source;
244244
if u < min || u > max {
245245
Err(TryFromIntError(()))
246246
} else {

src/libcore/num/mod.rs

+33-33
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,9 @@ $EndFeature, "
750750
}
751751

752752
doc_comment! {
753-
concat!("Unchecked integer addition. Computes `self + rhs, assuming overflow
753+
concat!("Unchecked integer addition. Computes `self + rhs`, assuming overflow
754754
cannot occur. This results in undefined behavior when `self + rhs > ", stringify!($SelfT),
755-
"::max_value()` or `self + rhs < ", stringify!($SelfT), "::min_value()`."),
755+
"::MAX` or `self + rhs < ", stringify!($SelfT), "::MIN`."),
756756
#[unstable(
757757
feature = "unchecked_math",
758758
reason = "niche optimization path",
@@ -792,9 +792,9 @@ $EndFeature, "
792792
}
793793

794794
doc_comment! {
795-
concat!("Unchecked integer subtraction. Computes `self - rhs, assuming overflow
795+
concat!("Unchecked integer subtraction. Computes `self - rhs`, assuming overflow
796796
cannot occur. This results in undefined behavior when `self - rhs > ", stringify!($SelfT),
797-
"::max_value()` or `self - rhs < ", stringify!($SelfT), "::min_value()`."),
797+
"::MAX` or `self - rhs < ", stringify!($SelfT), "::MIN`."),
798798
#[unstable(
799799
feature = "unchecked_math",
800800
reason = "niche optimization path",
@@ -834,9 +834,9 @@ $EndFeature, "
834834
}
835835

836836
doc_comment! {
837-
concat!("Unchecked integer multiplication. Computes `self * rhs, assuming overflow
837+
concat!("Unchecked integer multiplication. Computes `self * rhs`, assuming overflow
838838
cannot occur. This results in undefined behavior when `self * rhs > ", stringify!($SelfT),
839-
"::max_value()` or `self * rhs < ", stringify!($SelfT), "::min_value()`."),
839+
"::MAX` or `self * rhs < ", stringify!($SelfT), "::MIN`."),
840840
#[unstable(
841841
feature = "unchecked_math",
842842
reason = "niche optimization path",
@@ -871,7 +871,7 @@ $EndFeature, "
871871
without modifying the original"]
872872
#[inline]
873873
pub const fn checked_div(self, rhs: Self) -> Option<Self> {
874-
if rhs == 0 || (self == Self::min_value() && rhs == -1) {
874+
if rhs == 0 || (self == Self::MIN && rhs == -1) {
875875
None
876876
} else {
877877
// SAFETY: div by zero and by INT_MIN have been checked above
@@ -900,7 +900,7 @@ assert_eq!((1", stringify!($SelfT), ").checked_div_euclid(0), None);
900900
without modifying the original"]
901901
#[inline]
902902
pub const fn checked_div_euclid(self, rhs: Self) -> Option<Self> {
903-
if rhs == 0 || (self == Self::min_value() && rhs == -1) {
903+
if rhs == 0 || (self == Self::MIN && rhs == -1) {
904904
None
905905
} else {
906906
Some(self.div_euclid(rhs))
@@ -929,7 +929,7 @@ $EndFeature, "
929929
without modifying the original"]
930930
#[inline]
931931
pub const fn checked_rem(self, rhs: Self) -> Option<Self> {
932-
if rhs == 0 || (self == Self::min_value() && rhs == -1) {
932+
if rhs == 0 || (self == Self::MIN && rhs == -1) {
933933
None
934934
} else {
935935
// SAFETY: div by zero and by INT_MIN have been checked above
@@ -957,7 +957,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.checked_rem_euclid(-1), None);
957957
without modifying the original"]
958958
#[inline]
959959
pub const fn checked_rem_euclid(self, rhs: Self) -> Option<Self> {
960-
if rhs == 0 || (self == Self::min_value() && rhs == -1) {
960+
if rhs == 0 || (self == Self::MIN && rhs == -1) {
961961
None
962962
} else {
963963
Some(self.rem_euclid(rhs))
@@ -1236,9 +1236,9 @@ $EndFeature, "
12361236
match self.checked_mul(rhs) {
12371237
Some(x) => x,
12381238
None => if (self < 0) == (rhs < 0) {
1239-
Self::max_value()
1239+
Self::MAX
12401240
} else {
1241-
Self::min_value()
1241+
Self::MIN
12421242
}
12431243
}
12441244
}
@@ -1267,8 +1267,8 @@ $EndFeature, "
12671267
pub const fn saturating_pow(self, exp: u32) -> Self {
12681268
match self.checked_pow(exp) {
12691269
Some(x) => x,
1270-
None if self < 0 && exp % 2 == 1 => Self::min_value(),
1271-
None => Self::max_value(),
1270+
None if self < 0 && exp % 2 == 1 => Self::MIN,
1271+
None => Self::MAX,
12721272
}
12731273
}
12741274
}
@@ -1738,7 +1738,7 @@ $EndFeature, "
17381738
#[must_use = "this returns the result of the operation, \
17391739
without modifying the original"]
17401740
pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) {
1741-
if self == Self::min_value() && rhs == -1 {
1741+
if self == Self::MIN && rhs == -1 {
17421742
(self, true)
17431743
} else {
17441744
(self / rhs, false)
@@ -1771,7 +1771,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_div_euclid(-1), (", stringi
17711771
#[must_use = "this returns the result of the operation, \
17721772
without modifying the original"]
17731773
pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) {
1774-
if self == Self::min_value() && rhs == -1 {
1774+
if self == Self::MIN && rhs == -1 {
17751775
(self, true)
17761776
} else {
17771777
(self.div_euclid(rhs), false)
@@ -1805,7 +1805,7 @@ $EndFeature, "
18051805
#[must_use = "this returns the result of the operation, \
18061806
without modifying the original"]
18071807
pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
1808-
if self == Self::min_value() && rhs == -1 {
1808+
if self == Self::MIN && rhs == -1 {
18091809
(0, true)
18101810
} else {
18111811
(self % rhs, false)
@@ -1838,7 +1838,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem_euclid(-1), (0, true));
18381838
without modifying the original"]
18391839
#[inline]
18401840
pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) {
1841-
if self == Self::min_value() && rhs == -1 {
1841+
if self == Self::MIN && rhs == -1 {
18421842
(0, true)
18431843
} else {
18441844
(self.rem_euclid(rhs), false)
@@ -1869,8 +1869,8 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_neg(), (", stringify!($Self
18691869
#[allow(unused_attributes)]
18701870
#[allow_internal_unstable(const_if_match)]
18711871
pub const fn overflowing_neg(self) -> (Self, bool) {
1872-
if self == Self::min_value() {
1873-
(Self::min_value(), true)
1872+
if self == Self::MIN {
1873+
(Self::MIN, true)
18741874
} else {
18751875
(-self, false)
18761876
}
@@ -1952,7 +1952,7 @@ $EndFeature, "
19521952
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
19531953
#[inline]
19541954
pub const fn overflowing_abs(self) -> (Self, bool) {
1955-
(self.wrapping_abs(), self == Self::min_value())
1955+
(self.wrapping_abs(), self == Self::MIN)
19561956
}
19571957
}
19581958

@@ -2986,9 +2986,9 @@ assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);", $EndFeat
29862986
}
29872987

29882988
doc_comment! {
2989-
concat!("Unchecked integer addition. Computes `self + rhs, assuming overflow
2989+
concat!("Unchecked integer addition. Computes `self + rhs`, assuming overflow
29902990
cannot occur. This results in undefined behavior when `self + rhs > ", stringify!($SelfT),
2991-
"::max_value()` or `self + rhs < ", stringify!($SelfT), "::min_value()`."),
2991+
"::MAX` or `self + rhs < ", stringify!($SelfT), "::MIN`."),
29922992
#[unstable(
29932993
feature = "unchecked_math",
29942994
reason = "niche optimization path",
@@ -3026,9 +3026,9 @@ assert_eq!(0", stringify!($SelfT), ".checked_sub(1), None);", $EndFeature, "
30263026
}
30273027

30283028
doc_comment! {
3029-
concat!("Unchecked integer subtraction. Computes `self - rhs, assuming overflow
3029+
concat!("Unchecked integer subtraction. Computes `self - rhs`, assuming overflow
30303030
cannot occur. This results in undefined behavior when `self - rhs > ", stringify!($SelfT),
3031-
"::max_value()` or `self - rhs < ", stringify!($SelfT), "::min_value()`."),
3031+
"::MAX` or `self - rhs < ", stringify!($SelfT), "::MIN`."),
30323032
#[unstable(
30333033
feature = "unchecked_math",
30343034
reason = "niche optimization path",
@@ -3066,9 +3066,9 @@ assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(2), None);", $EndFeature, "
30663066
}
30673067

30683068
doc_comment! {
3069-
concat!("Unchecked integer multiplication. Computes `self * rhs, assuming overflow
3069+
concat!("Unchecked integer multiplication. Computes `self * rhs`, assuming overflow
30703070
cannot occur. This results in undefined behavior when `self * rhs > ", stringify!($SelfT),
3071-
"::max_value()` or `self * rhs < ", stringify!($SelfT), "::min_value()`."),
3071+
"::MAX` or `self * rhs < ", stringify!($SelfT), "::MIN`."),
30723072
#[unstable(
30733073
feature = "unchecked_math",
30743074
reason = "niche optimization path",
@@ -3367,7 +3367,7 @@ assert_eq!((", stringify!($SelfT), "::MAX).saturating_mul(10), ", stringify!($Se
33673367
pub const fn saturating_mul(self, rhs: Self) -> Self {
33683368
match self.checked_mul(rhs) {
33693369
Some(x) => x,
3370-
None => Self::max_value(),
3370+
None => Self::MAX,
33713371
}
33723372
}
33733373
}
@@ -3394,7 +3394,7 @@ $EndFeature, "
33943394
pub const fn saturating_pow(self, exp: u32) -> Self {
33953395
match self.checked_pow(exp) {
33963396
Some(x) => x,
3397-
None => Self::max_value(),
3397+
None => Self::MAX,
33983398
}
33993399
}
34003400
}
@@ -4081,7 +4081,7 @@ Basic usage:
40814081
}
40824082
}
40834083

4084-
doc_comment! {
4084+
doc_comment! {
40854085
concat!("Performs Euclidean division.
40864086
40874087
Since, for the positive integers, all common
@@ -4179,7 +4179,7 @@ assert!(!10", stringify!($SelfT), ".is_power_of_two());", $EndFeature, "
41794179
// (such as intel pre-haswell) have more efficient ctlz
41804180
// intrinsics when the argument is non-zero.
41814181
let z = unsafe { intrinsics::ctlz_nonzero(p) };
4182-
<$SelfT>::max_value() >> z
4182+
<$SelfT>::MAX >> z
41834183
}
41844184

41854185
doc_comment! {
@@ -5161,9 +5161,9 @@ trait FromStrRadixHelper: PartialOrd + Copy {
51615161
macro_rules! doit {
51625162
($($t:ty)*) => ($(impl FromStrRadixHelper for $t {
51635163
#[inline]
5164-
fn min_value() -> Self { Self::min_value() }
5164+
fn min_value() -> Self { Self::MIN }
51655165
#[inline]
5166-
fn max_value() -> Self { Self::max_value() }
5166+
fn max_value() -> Self { Self::MAX }
51675167
#[inline]
51685168
fn from_u32(u: u32) -> Self { u as Self }
51695169
#[inline]

0 commit comments

Comments
 (0)