Skip to content

Commit 7c15f30

Browse files
authored
Rollup merge of #72906 - lzutao:migrate-numeric-assoc-consts, r=dtolnay
Migrate to numeric associated consts The deprecation PR is #72885 cc #68490 cc rust-lang/rfcs#2700
2 parents e2e2a0f + c9bd35c commit 7c15f30

File tree

6 files changed

+51
-51
lines changed

6 files changed

+51
-51
lines changed

clippy_lints/src/consts.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
254254
if let ["core", "num", int_impl, "max_value"] = *def_path;
255255
then {
256256
let value = match int_impl {
257-
"<impl i8>" => i8::max_value() as u128,
258-
"<impl i16>" => i16::max_value() as u128,
259-
"<impl i32>" => i32::max_value() as u128,
260-
"<impl i64>" => i64::max_value() as u128,
261-
"<impl i128>" => i128::max_value() as u128,
257+
"<impl i8>" => i8::MAX as u128,
258+
"<impl i16>" => i16::MAX as u128,
259+
"<impl i32>" => i32::MAX as u128,
260+
"<impl i64>" => i64::MAX as u128,
261+
"<impl i128>" => i128::MAX as u128,
262262
_ => return None,
263263
};
264264
Some(Constant::Int(value))

clippy_lints/src/enum_clike.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
6565
continue;
6666
}
6767
},
68-
ty::Uint(UintTy::Usize) if val > u128::from(u32::max_value()) => {},
68+
ty::Uint(UintTy::Usize) if val > u128::from(u32::MAX) => {},
6969
_ => continue,
7070
}
7171
span_lint(

clippy_lints/src/types.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -1946,18 +1946,18 @@ fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_
19461946
let which = match (&ty.kind, cv) {
19471947
(&ty::Bool, Constant::Bool(false)) | (&ty::Uint(_), Constant::Int(0)) => Minimum,
19481948
(&ty::Int(ity), Constant::Int(i))
1949-
if i == unsext(cx.tcx, i128::min_value() >> (128 - int_bits(cx.tcx, ity)), ity) =>
1949+
if i == unsext(cx.tcx, i128::MIN >> (128 - int_bits(cx.tcx, ity)), ity) =>
19501950
{
19511951
Minimum
19521952
},
19531953

19541954
(&ty::Bool, Constant::Bool(true)) => Maximum,
19551955
(&ty::Int(ity), Constant::Int(i))
1956-
if i == unsext(cx.tcx, i128::max_value() >> (128 - int_bits(cx.tcx, ity)), ity) =>
1956+
if i == unsext(cx.tcx, i128::MAX >> (128 - int_bits(cx.tcx, ity)), ity) =>
19571957
{
19581958
Maximum
19591959
},
1960-
(&ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::max_value(), uty) == i => Maximum,
1960+
(&ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::MAX, uty) == i => Maximum,
19611961

19621962
_ => return None,
19631963
};
@@ -2039,7 +2039,7 @@ impl FullInt {
20392039
fn cmp_s_u(s: i128, u: u128) -> Ordering {
20402040
if s < 0 {
20412041
Ordering::Less
2042-
} else if u > (i128::max_value() as u128) {
2042+
} else if u > (i128::MAX as u128) {
20432043
Ordering::Greater
20442044
} else {
20452045
(s as u128).cmp(&u)
@@ -2084,48 +2084,48 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>)
20842084
match pre_cast_ty.kind {
20852085
ty::Int(int_ty) => Some(match int_ty {
20862086
IntTy::I8 => (
2087-
FullInt::S(i128::from(i8::min_value())),
2088-
FullInt::S(i128::from(i8::max_value())),
2087+
FullInt::S(i128::from(i8::MIN)),
2088+
FullInt::S(i128::from(i8::MAX)),
20892089
),
20902090
IntTy::I16 => (
2091-
FullInt::S(i128::from(i16::min_value())),
2092-
FullInt::S(i128::from(i16::max_value())),
2091+
FullInt::S(i128::from(i16::MIN)),
2092+
FullInt::S(i128::from(i16::MAX)),
20932093
),
20942094
IntTy::I32 => (
2095-
FullInt::S(i128::from(i32::min_value())),
2096-
FullInt::S(i128::from(i32::max_value())),
2095+
FullInt::S(i128::from(i32::MIN)),
2096+
FullInt::S(i128::from(i32::MAX)),
20972097
),
20982098
IntTy::I64 => (
2099-
FullInt::S(i128::from(i64::min_value())),
2100-
FullInt::S(i128::from(i64::max_value())),
2099+
FullInt::S(i128::from(i64::MIN)),
2100+
FullInt::S(i128::from(i64::MAX)),
21012101
),
2102-
IntTy::I128 => (FullInt::S(i128::min_value()), FullInt::S(i128::max_value())),
2102+
IntTy::I128 => (FullInt::S(i128::MIN), FullInt::S(i128::MAX)),
21032103
IntTy::Isize => (
2104-
FullInt::S(isize::min_value() as i128),
2105-
FullInt::S(isize::max_value() as i128),
2104+
FullInt::S(isize::MIN as i128),
2105+
FullInt::S(isize::MAX as i128),
21062106
),
21072107
}),
21082108
ty::Uint(uint_ty) => Some(match uint_ty {
21092109
UintTy::U8 => (
2110-
FullInt::U(u128::from(u8::min_value())),
2111-
FullInt::U(u128::from(u8::max_value())),
2110+
FullInt::U(u128::from(u8::MIN)),
2111+
FullInt::U(u128::from(u8::MAX)),
21122112
),
21132113
UintTy::U16 => (
2114-
FullInt::U(u128::from(u16::min_value())),
2115-
FullInt::U(u128::from(u16::max_value())),
2114+
FullInt::U(u128::from(u16::MIN)),
2115+
FullInt::U(u128::from(u16::MAX)),
21162116
),
21172117
UintTy::U32 => (
2118-
FullInt::U(u128::from(u32::min_value())),
2119-
FullInt::U(u128::from(u32::max_value())),
2118+
FullInt::U(u128::from(u32::MIN)),
2119+
FullInt::U(u128::from(u32::MAX)),
21202120
),
21212121
UintTy::U64 => (
2122-
FullInt::U(u128::from(u64::min_value())),
2123-
FullInt::U(u128::from(u64::max_value())),
2122+
FullInt::U(u128::from(u64::MIN)),
2123+
FullInt::U(u128::from(u64::MAX)),
21242124
),
2125-
UintTy::U128 => (FullInt::U(u128::min_value()), FullInt::U(u128::max_value())),
2125+
UintTy::U128 => (FullInt::U(u128::MIN), FullInt::U(u128::MAX)),
21262126
UintTy::Usize => (
2127-
FullInt::U(usize::min_value() as u128),
2128-
FullInt::U(usize::max_value() as u128),
2127+
FullInt::U(usize::MIN as u128),
2128+
FullInt::U(usize::MAX as u128),
21292129
),
21302130
}),
21312131
_ => None,

tests/ui/cast.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ fn main() {
3737
1isize as usize;
3838
-1isize as usize;
3939
0i8 as u8;
40-
i8::max_value() as u8;
41-
i16::max_value() as u16;
42-
i32::max_value() as u32;
43-
i64::max_value() as u64;
44-
i128::max_value() as u128;
40+
i8::MAX as u8;
41+
i16::MAX as u16;
42+
i32::MAX as u32;
43+
i64::MAX as u64;
44+
i128::MAX as u128;
4545

4646
(-1i8).abs() as u8;
4747
(-1i16).abs() as u16;

tests/ui/implicit_saturating_sub.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn main() {
110110
}
111111

112112
// Lint
113-
if i_8 > i8::min_value() {
113+
if i_8 > i8::MIN {
114114
i_8 -= 1;
115115
}
116116

@@ -120,7 +120,7 @@ fn main() {
120120
}
121121

122122
// Lint
123-
if i_8 != i8::min_value() {
123+
if i_8 != i8::MIN {
124124
i_8 -= 1;
125125
}
126126

@@ -135,7 +135,7 @@ fn main() {
135135
}
136136

137137
// Lint
138-
if i_16 > i16::min_value() {
138+
if i_16 > i16::MIN {
139139
i_16 -= 1;
140140
}
141141

@@ -145,7 +145,7 @@ fn main() {
145145
}
146146

147147
// Lint
148-
if i_16 != i16::min_value() {
148+
if i_16 != i16::MIN {
149149
i_16 -= 1;
150150
}
151151

@@ -160,7 +160,7 @@ fn main() {
160160
}
161161

162162
// Lint
163-
if i_32 > i32::min_value() {
163+
if i_32 > i32::MIN {
164164
i_32 -= 1;
165165
}
166166

@@ -170,7 +170,7 @@ fn main() {
170170
}
171171

172172
// Lint
173-
if i_32 != i32::min_value() {
173+
if i_32 != i32::MIN {
174174
i_32 -= 1;
175175
}
176176

@@ -180,7 +180,7 @@ fn main() {
180180
let mut i_64: i64 = endi_64 - starti_64;
181181

182182
// Lint
183-
if i64::min_value() < i_64 {
183+
if i64::MIN < i_64 {
184184
i_64 -= 1;
185185
}
186186

tests/ui/implicit_saturating_sub.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ LL | | }
7575
error: Implicitly performing saturating subtraction
7676
--> $DIR/implicit_saturating_sub.rs:113:5
7777
|
78-
LL | / if i_8 > i8::min_value() {
78+
LL | / if i_8 > i8::MIN {
7979
LL | | i_8 -= 1;
8080
LL | | }
8181
| |_____^ help: try: `i_8 = i_8.saturating_sub(1);`
@@ -91,7 +91,7 @@ LL | | }
9191
error: Implicitly performing saturating subtraction
9292
--> $DIR/implicit_saturating_sub.rs:123:5
9393
|
94-
LL | / if i_8 != i8::min_value() {
94+
LL | / if i_8 != i8::MIN {
9595
LL | | i_8 -= 1;
9696
LL | | }
9797
| |_____^ help: try: `i_8 = i_8.saturating_sub(1);`
@@ -107,7 +107,7 @@ LL | | }
107107
error: Implicitly performing saturating subtraction
108108
--> $DIR/implicit_saturating_sub.rs:138:5
109109
|
110-
LL | / if i_16 > i16::min_value() {
110+
LL | / if i_16 > i16::MIN {
111111
LL | | i_16 -= 1;
112112
LL | | }
113113
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
@@ -123,7 +123,7 @@ LL | | }
123123
error: Implicitly performing saturating subtraction
124124
--> $DIR/implicit_saturating_sub.rs:148:5
125125
|
126-
LL | / if i_16 != i16::min_value() {
126+
LL | / if i_16 != i16::MIN {
127127
LL | | i_16 -= 1;
128128
LL | | }
129129
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
@@ -139,7 +139,7 @@ LL | | }
139139
error: Implicitly performing saturating subtraction
140140
--> $DIR/implicit_saturating_sub.rs:163:5
141141
|
142-
LL | / if i_32 > i32::min_value() {
142+
LL | / if i_32 > i32::MIN {
143143
LL | | i_32 -= 1;
144144
LL | | }
145145
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
@@ -155,15 +155,15 @@ LL | | }
155155
error: Implicitly performing saturating subtraction
156156
--> $DIR/implicit_saturating_sub.rs:173:5
157157
|
158-
LL | / if i_32 != i32::min_value() {
158+
LL | / if i_32 != i32::MIN {
159159
LL | | i_32 -= 1;
160160
LL | | }
161161
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
162162

163163
error: Implicitly performing saturating subtraction
164164
--> $DIR/implicit_saturating_sub.rs:183:5
165165
|
166-
LL | / if i64::min_value() < i_64 {
166+
LL | / if i64::MIN < i_64 {
167167
LL | | i_64 -= 1;
168168
LL | | }
169169
| |_____^ help: try: `i_64 = i_64.saturating_sub(1);`

0 commit comments

Comments
 (0)