Skip to content

Commit eb42f3e

Browse files
committed
Pack the u128 in LitKind::Int
1 parent 21d719d commit eb42f3e

20 files changed

+46
-35
lines changed

clippy_lints/src/casts/unnecessary_cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub(super) fn check<'tcx>(
107107
&& let Some(src) = snippet_opt(cx, cast_expr.span)
108108
&& cast_to.is_floating_point()
109109
&& let Some(num_lit) = NumericLiteral::from_lit_kind(&src, &lit.node)
110-
&& let from_nbits = 128 - n.leading_zeros()
110+
&& let from_nbits = 128 - n.get().leading_zeros()
111111
&& let to_nbits = fp_ty_mantissa_nbits(cast_to)
112112
&& from_nbits != 0
113113
&& to_nbits != 0

clippy_lints/src/implicit_saturating_add.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::get_parent_expr;
44
use clippy_utils::source::snippet_with_context;
55
use rustc_ast::ast::{LitIntType, LitKind};
6+
use rustc_data_structures::packed::Pu128;
67
use rustc_errors::Applicability;
78
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind};
89
use rustc_lint::{LateContext, LateLintPass};
@@ -69,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd {
6970
&& clippy_utils::SpanlessEq::new(cx).eq_expr(l, target)
7071
&& BinOpKind::Add == op1.node
7172
&& let ExprKind::Lit(lit) = value.kind
72-
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
73+
&& let LitKind::Int(Pu128(1), LitIntType::Unsuffixed) = lit.node
7374
&& block.expr.is_none()
7475
{
7576
let mut app = Applicability::MachineApplicable;

clippy_lints/src/implicit_saturating_sub.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::{higher, is_integer_literal, peel_blocks_with_stmt, SpanlessEq};
33
use rustc_ast::ast::LitKind;
4+
use rustc_data_structures::packed::Pu128;
45
use rustc_errors::Applicability;
56
use rustc_hir::{BinOpKind, Expr, ExprKind, QPath};
67
use rustc_lint::{LateContext, LateLintPass};
@@ -86,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
8687
match cond_num_val.kind {
8788
ExprKind::Lit(cond_lit) => {
8889
// Check if the constant is zero
89-
if let LitKind::Int(0, _) = cond_lit.node {
90+
if let LitKind::Int(Pu128(0), _) = cond_lit.node {
9091
if cx.typeck_results().expr_ty(cond_left).is_signed() {
9192
} else {
9293
print_lint_and_sugg(cx, var_name, expr);

clippy_lints/src/loops/manual_memcpy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ fn is_array_length_equal_to_range(cx: &LateContext<'_>, start: &Expr<'_>, end: &
461461
if let ExprKind::Lit(lit) = expr.kind
462462
&& let ast::LitKind::Int(value, _) = lit.node
463463
{
464-
Some(value)
464+
Some(value.get())
465465
} else {
466466
None
467467
}

clippy_lints/src/loops/needless_range_loop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ fn is_end_eq_array_len<'tcx>(
209209
&& let Some(arr_len) = arr_len_const.try_eval_target_usize(cx.tcx, cx.param_env)
210210
{
211211
return match limits {
212-
ast::RangeLimits::Closed => end_int + 1 >= arr_len.into(),
213-
ast::RangeLimits::HalfOpen => end_int >= arr_len.into(),
212+
ast::RangeLimits::Closed => end_int.get() + 1 >= arr_len.into(),
213+
ast::RangeLimits::HalfOpen => end_int.get() >= arr_len.into(),
214214
};
215215
}
216216

clippy_lints/src/manual_bits.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::get_parent_expr;
44
use clippy_utils::source::snippet_with_context;
55
use rustc_ast::ast::LitKind;
6+
use rustc_data_structures::packed::Pu128;
67
use rustc_errors::Applicability;
78
use rustc_hir::{BinOpKind, Expr, ExprKind, GenericArg, QPath};
89
use rustc_lint::{LateContext, LateLintPass, LintContext};
@@ -62,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualBits {
6263
&& let Some((real_ty, resolved_ty, other_expr)) = get_one_size_of_ty(cx, left_expr, right_expr)
6364
&& matches!(resolved_ty.kind(), ty::Int(_) | ty::Uint(_))
6465
&& let ExprKind::Lit(lit) = &other_expr.kind
65-
&& let LitKind::Int(8, _) = lit.node
66+
&& let LitKind::Int(Pu128(8), _) = lit.node
6667
{
6768
let mut app = Applicability::MachineApplicable;
6869
let ty_snip = snippet_with_context(cx, real_ty.span, ctxt, "..", &mut app).0;

clippy_lints/src/manual_range_patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn expr_as_i128(expr: &Expr<'_>) -> Option<i128> {
4545
&& let LitKind::Int(num, _) = lit.node
4646
{
4747
// Intentionally not handling numbers greater than i128::MAX (for u128 literals) for now.
48-
num.try_into().ok()
48+
num.get().try_into().ok()
4949
} else {
5050
None
5151
}

clippy_lints/src/manual_strip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn eq_pattern_length<'tcx>(cx: &LateContext<'tcx>, pattern: &Expr<'_>, expr: &'t
161161
..
162162
}) = expr.kind
163163
{
164-
constant_length(cx, pattern).map_or(false, |length| length == *n)
164+
constant_length(cx, pattern).map_or(false, |length| *n == length)
165165
} else {
166166
len_arg(cx, expr).map_or(false, |arg| eq_expr_value(cx, pattern, arg))
167167
}

clippy_lints/src/matches/match_same_arms.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl<'a> NormalizedPat<'a> {
293293
LitKind::ByteStr(ref bytes, _) | LitKind::CStr(ref bytes, _) => Self::LitBytes(bytes),
294294
LitKind::Byte(val) => Self::LitInt(val.into()),
295295
LitKind::Char(val) => Self::LitInt(val.into()),
296-
LitKind::Int(val, _) => Self::LitInt(val),
296+
LitKind::Int(val, _) => Self::LitInt(val.get()),
297297
LitKind::Bool(val) => Self::LitBool(val),
298298
LitKind::Float(..) | LitKind::Err => Self::Wild,
299299
},
@@ -305,7 +305,7 @@ impl<'a> NormalizedPat<'a> {
305305
None => 0,
306306
Some(e) => match &e.kind {
307307
ExprKind::Lit(lit) => match lit.node {
308-
LitKind::Int(val, _) => val,
308+
LitKind::Int(val, _) => val.get(),
309309
LitKind::Char(val) => val.into(),
310310
LitKind::Byte(val) => val.into(),
311311
_ => return Self::Wild,
@@ -317,7 +317,7 @@ impl<'a> NormalizedPat<'a> {
317317
None => (u128::MAX, RangeEnd::Included),
318318
Some(e) => match &e.kind {
319319
ExprKind::Lit(lit) => match lit.node {
320-
LitKind::Int(val, _) => (val, bounds),
320+
LitKind::Int(val, _) => (val.get(), bounds),
321321
LitKind::Char(val) => (val.into(), bounds),
322322
LitKind::Byte(val) => (val.into(), bounds),
323323
_ => return Self::Wild,

clippy_lints/src/methods/get_first.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_applicability;
33
use clippy_utils::ty::is_type_diagnostic_item;
44
use rustc_ast::LitKind;
5+
use rustc_data_structures::packed::Pu128;
56
use rustc_errors::Applicability;
67
use rustc_hir as hir;
78
use rustc_lint::LateContext;
@@ -20,7 +21,7 @@ pub(super) fn check<'tcx>(
2021
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
2122
&& let identity = cx.tcx.type_of(impl_id).instantiate_identity()
2223
&& let hir::ExprKind::Lit(Spanned {
23-
node: LitKind::Int(0, _),
24+
node: LitKind::Int(Pu128(0), _),
2425
..
2526
}) = arg.kind
2627
{

0 commit comments

Comments
 (0)