Migrate to numeric associated consts

This commit is contained in:
Lzu Tao 2020-06-02 07:59:11 +00:00
parent 8db24840f7
commit c9bd35cac3
6 changed files with 51 additions and 51 deletions

View file

@ -254,11 +254,11 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
if let ["core", "num", int_impl, "max_value"] = *def_path;
then {
let value = match int_impl {
"<impl i8>" => i8::max_value() as u128,
"<impl i16>" => i16::max_value() as u128,
"<impl i32>" => i32::max_value() as u128,
"<impl i64>" => i64::max_value() as u128,
"<impl i128>" => i128::max_value() as u128,
"<impl i8>" => i8::MAX as u128,
"<impl i16>" => i16::MAX as u128,
"<impl i32>" => i32::MAX as u128,
"<impl i64>" => i64::MAX as u128,
"<impl i128>" => i128::MAX as u128,
_ => return None,
};
Some(Constant::Int(value))

View file

@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
continue;
}
},
ty::Uint(UintTy::Usize) if val > u128::from(u32::max_value()) => {},
ty::Uint(UintTy::Usize) if val > u128::from(u32::MAX) => {},
_ => continue,
}
span_lint(

View file

@ -1946,18 +1946,18 @@ fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_
let which = match (&ty.kind, cv) {
(&ty::Bool, Constant::Bool(false)) | (&ty::Uint(_), Constant::Int(0)) => Minimum,
(&ty::Int(ity), Constant::Int(i))
if i == unsext(cx.tcx, i128::min_value() >> (128 - int_bits(cx.tcx, ity)), ity) =>
if i == unsext(cx.tcx, i128::MIN >> (128 - int_bits(cx.tcx, ity)), ity) =>
{
Minimum
},
(&ty::Bool, Constant::Bool(true)) => Maximum,
(&ty::Int(ity), Constant::Int(i))
if i == unsext(cx.tcx, i128::max_value() >> (128 - int_bits(cx.tcx, ity)), ity) =>
if i == unsext(cx.tcx, i128::MAX >> (128 - int_bits(cx.tcx, ity)), ity) =>
{
Maximum
},
(&ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::max_value(), uty) == i => Maximum,
(&ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::MAX, uty) == i => Maximum,
_ => return None,
};
@ -2039,7 +2039,7 @@ impl FullInt {
fn cmp_s_u(s: i128, u: u128) -> Ordering {
if s < 0 {
Ordering::Less
} else if u > (i128::max_value() as u128) {
} else if u > (i128::MAX as u128) {
Ordering::Greater
} else {
(s as u128).cmp(&u)
@ -2084,48 +2084,48 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>)
match pre_cast_ty.kind {
ty::Int(int_ty) => Some(match int_ty {
IntTy::I8 => (
FullInt::S(i128::from(i8::min_value())),
FullInt::S(i128::from(i8::max_value())),
FullInt::S(i128::from(i8::MIN)),
FullInt::S(i128::from(i8::MAX)),
),
IntTy::I16 => (
FullInt::S(i128::from(i16::min_value())),
FullInt::S(i128::from(i16::max_value())),
FullInt::S(i128::from(i16::MIN)),
FullInt::S(i128::from(i16::MAX)),
),
IntTy::I32 => (
FullInt::S(i128::from(i32::min_value())),
FullInt::S(i128::from(i32::max_value())),
FullInt::S(i128::from(i32::MIN)),
FullInt::S(i128::from(i32::MAX)),
),
IntTy::I64 => (
FullInt::S(i128::from(i64::min_value())),
FullInt::S(i128::from(i64::max_value())),
FullInt::S(i128::from(i64::MIN)),
FullInt::S(i128::from(i64::MAX)),
),
IntTy::I128 => (FullInt::S(i128::min_value()), FullInt::S(i128::max_value())),
IntTy::I128 => (FullInt::S(i128::MIN), FullInt::S(i128::MAX)),
IntTy::Isize => (
FullInt::S(isize::min_value() as i128),
FullInt::S(isize::max_value() as i128),
FullInt::S(isize::MIN as i128),
FullInt::S(isize::MAX as i128),
),
}),
ty::Uint(uint_ty) => Some(match uint_ty {
UintTy::U8 => (
FullInt::U(u128::from(u8::min_value())),
FullInt::U(u128::from(u8::max_value())),
FullInt::U(u128::from(u8::MIN)),
FullInt::U(u128::from(u8::MAX)),
),
UintTy::U16 => (
FullInt::U(u128::from(u16::min_value())),
FullInt::U(u128::from(u16::max_value())),
FullInt::U(u128::from(u16::MIN)),
FullInt::U(u128::from(u16::MAX)),
),
UintTy::U32 => (
FullInt::U(u128::from(u32::min_value())),
FullInt::U(u128::from(u32::max_value())),
FullInt::U(u128::from(u32::MIN)),
FullInt::U(u128::from(u32::MAX)),
),
UintTy::U64 => (
FullInt::U(u128::from(u64::min_value())),
FullInt::U(u128::from(u64::max_value())),
FullInt::U(u128::from(u64::MIN)),
FullInt::U(u128::from(u64::MAX)),
),
UintTy::U128 => (FullInt::U(u128::min_value()), FullInt::U(u128::max_value())),
UintTy::U128 => (FullInt::U(u128::MIN), FullInt::U(u128::MAX)),
UintTy::Usize => (
FullInt::U(usize::min_value() as u128),
FullInt::U(usize::max_value() as u128),
FullInt::U(usize::MIN as u128),
FullInt::U(usize::MAX as u128),
),
}),
_ => None,

View file

@ -37,11 +37,11 @@ fn main() {
1isize as usize;
-1isize as usize;
0i8 as u8;
i8::max_value() as u8;
i16::max_value() as u16;
i32::max_value() as u32;
i64::max_value() as u64;
i128::max_value() as u128;
i8::MAX as u8;
i16::MAX as u16;
i32::MAX as u32;
i64::MAX as u64;
i128::MAX as u128;
(-1i8).abs() as u8;
(-1i16).abs() as u16;

View file

@ -110,7 +110,7 @@ fn main() {
}
// Lint
if i_8 > i8::min_value() {
if i_8 > i8::MIN {
i_8 -= 1;
}
@ -120,7 +120,7 @@ fn main() {
}
// Lint
if i_8 != i8::min_value() {
if i_8 != i8::MIN {
i_8 -= 1;
}
@ -135,7 +135,7 @@ fn main() {
}
// Lint
if i_16 > i16::min_value() {
if i_16 > i16::MIN {
i_16 -= 1;
}
@ -145,7 +145,7 @@ fn main() {
}
// Lint
if i_16 != i16::min_value() {
if i_16 != i16::MIN {
i_16 -= 1;
}
@ -160,7 +160,7 @@ fn main() {
}
// Lint
if i_32 > i32::min_value() {
if i_32 > i32::MIN {
i_32 -= 1;
}
@ -170,7 +170,7 @@ fn main() {
}
// Lint
if i_32 != i32::min_value() {
if i_32 != i32::MIN {
i_32 -= 1;
}
@ -180,7 +180,7 @@ fn main() {
let mut i_64: i64 = endi_64 - starti_64;
// Lint
if i64::min_value() < i_64 {
if i64::MIN < i_64 {
i_64 -= 1;
}

View file

@ -75,7 +75,7 @@ LL | | }
error: Implicitly performing saturating subtraction
--> $DIR/implicit_saturating_sub.rs:113:5
|
LL | / if i_8 > i8::min_value() {
LL | / if i_8 > i8::MIN {
LL | | i_8 -= 1;
LL | | }
| |_____^ help: try: `i_8 = i_8.saturating_sub(1);`
@ -91,7 +91,7 @@ LL | | }
error: Implicitly performing saturating subtraction
--> $DIR/implicit_saturating_sub.rs:123:5
|
LL | / if i_8 != i8::min_value() {
LL | / if i_8 != i8::MIN {
LL | | i_8 -= 1;
LL | | }
| |_____^ help: try: `i_8 = i_8.saturating_sub(1);`
@ -107,7 +107,7 @@ LL | | }
error: Implicitly performing saturating subtraction
--> $DIR/implicit_saturating_sub.rs:138:5
|
LL | / if i_16 > i16::min_value() {
LL | / if i_16 > i16::MIN {
LL | | i_16 -= 1;
LL | | }
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
@ -123,7 +123,7 @@ LL | | }
error: Implicitly performing saturating subtraction
--> $DIR/implicit_saturating_sub.rs:148:5
|
LL | / if i_16 != i16::min_value() {
LL | / if i_16 != i16::MIN {
LL | | i_16 -= 1;
LL | | }
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
@ -139,7 +139,7 @@ LL | | }
error: Implicitly performing saturating subtraction
--> $DIR/implicit_saturating_sub.rs:163:5
|
LL | / if i_32 > i32::min_value() {
LL | / if i_32 > i32::MIN {
LL | | i_32 -= 1;
LL | | }
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
@ -155,7 +155,7 @@ LL | | }
error: Implicitly performing saturating subtraction
--> $DIR/implicit_saturating_sub.rs:173:5
|
LL | / if i_32 != i32::min_value() {
LL | / if i_32 != i32::MIN {
LL | | i_32 -= 1;
LL | | }
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
@ -163,7 +163,7 @@ LL | | }
error: Implicitly performing saturating subtraction
--> $DIR/implicit_saturating_sub.rs:183:5
|
LL | / if i64::min_value() < i_64 {
LL | / if i64::MIN < i_64 {
LL | | i_64 -= 1;
LL | | }
| |_____^ help: try: `i_64 = i_64.saturating_sub(1);`