Skip to content

Commit

Permalink
Rollup merge of rust-lang#72906 - lzutao:migrate-numeric-assoc-consts…
Browse files Browse the repository at this point in the history
…, r=dtolnay

Migrate to numeric associated consts

The deprecation PR is rust-lang#72885

cc rust-lang#68490
cc rust-lang/rfcs#2700
  • Loading branch information
Dylan-DPC authored Jun 12, 2020
2 parents e2e2a0f + c9bd35c commit 7c15f30
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 51 deletions.
10 changes: 5 additions & 5 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/enum_clike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
52 changes: 26 additions & 26 deletions clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions tests/ui/implicit_saturating_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn main() {
}

// Lint
if i_8 > i8::min_value() {
if i_8 > i8::MIN {
i_8 -= 1;
}

Expand All @@ -120,7 +120,7 @@ fn main() {
}

// Lint
if i_8 != i8::min_value() {
if i_8 != i8::MIN {
i_8 -= 1;
}

Expand All @@ -135,7 +135,7 @@ fn main() {
}

// Lint
if i_16 > i16::min_value() {
if i_16 > i16::MIN {
i_16 -= 1;
}

Expand All @@ -145,7 +145,7 @@ fn main() {
}

// Lint
if i_16 != i16::min_value() {
if i_16 != i16::MIN {
i_16 -= 1;
}

Expand All @@ -160,7 +160,7 @@ fn main() {
}

// Lint
if i_32 > i32::min_value() {
if i_32 > i32::MIN {
i_32 -= 1;
}

Expand All @@ -170,7 +170,7 @@ fn main() {
}

// Lint
if i_32 != i32::min_value() {
if i_32 != i32::MIN {
i_32 -= 1;
}

Expand All @@ -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;
}

Expand Down
14 changes: 7 additions & 7 deletions tests/ui/implicit_saturating_sub.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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);`
Expand All @@ -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);`
Expand All @@ -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);`
Expand All @@ -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);`
Expand All @@ -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);`
Expand All @@ -155,15 +155,15 @@ 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);`

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);`
Expand Down

0 comments on commit 7c15f30

Please sign in to comment.