Skip to content

Commit 8d80820

Browse files
committed
dont disable lint on i128
1 parent ac59e76 commit 8d80820

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

clippy_lints/src/casts/cast_lossless.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use clippy_utils::ty::is_isize_or_usize;
66
use rustc_errors::Applicability;
77
use rustc_hir::{Expr, ExprKind, QPath, TyKind};
88
use rustc_lint::LateContext;
9-
use rustc_middle::ty::{self, FloatTy, IntTy, Ty, UintTy};
9+
use rustc_middle::ty::{self, FloatTy, Ty, UintTy};
1010

1111
use super::{utils, CAST_LOSSLESS};
1212

@@ -78,12 +78,9 @@ pub(super) fn check(
7878
fn should_lint(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, msrv: &Msrv) -> bool {
7979
// Do not suggest using From in consts/statics until it is valid to do so (see #2267).
8080
//
81-
// If destination is (U)int128, do not lint because source type cannot be larger
81+
// If destination is u128, do not lint because source type cannot be larger
8282
// If source is bool, still lint due to the lint message differing (refers to style)
83-
if in_constant(cx, expr.hir_id)
84-
|| (!cast_from.is_bool()
85-
&& (matches!(cast_to.kind(), ty::Int(IntTy::I128)) || matches!(cast_to.kind(), ty::Uint(UintTy::U128))))
86-
{
83+
if in_constant(cx, expr.hir_id) || (!cast_from.is_bool() && matches!(cast_to.kind(), ty::Uint(UintTy::U128))) {
8784
return false;
8885
}
8986

tests/ui/cast_lossless_integer.fixed

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ fn main() {
3030

3131
let _ = I64::from(1i8);
3232

33-
// Do not lint if destination type is (U)128
33+
// Do not lint if destination type is u128
3434
// see https://github.com/rust-lang/rust-clippy/issues/12492
35-
let _ = 1i8 as i128;
3635
let _ = 1u8 as u128;
3736
let _ = 1u8 as U128;
3837
}

tests/ui/cast_lossless_integer.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ fn main() {
3030

3131
let _ = 1i8 as I64;
3232

33-
// Do not lint if destination type is (U)128
33+
// Do not lint if destination type is u128
3434
// see https://github.com/rust-lang/rust-clippy/issues/12492
35-
let _ = 1i8 as i128;
3635
let _ = 1u8 as u128;
3736
let _ = 1u8 as U128;
3837
}

tests/ui/cast_lossless_integer.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ LL | let _ = 1i8 as I64;
122122
| ^^^^^^^^^^ help: try: `I64::from(1i8)`
123123

124124
error: casting `i8` to `i32` may become silently lossy if you later change the type
125-
--> tests/ui/cast_lossless_integer.rs:71:13
125+
--> tests/ui/cast_lossless_integer.rs:70:13
126126
|
127127
LL | let _ = sign_cast!(x, u8, i8) as i32;
128128
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::from(sign_cast!(x, u8, i8))`
129129

130130
error: casting `i8` to `i32` may become silently lossy if you later change the type
131-
--> tests/ui/cast_lossless_integer.rs:72:13
131+
--> tests/ui/cast_lossless_integer.rs:71:13
132132
|
133133
LL | let _ = (sign_cast!(x, u8, i8) + 1) as i32;
134134
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::from(sign_cast!(x, u8, i8) + 1)`

0 commit comments

Comments
 (0)