Skip to content

Commit 477f5f5

Browse files
committed
Revert "Pack the u128 in LitKind::Int"
This reverts commit 6718116.
1 parent 6718116 commit 477f5f5

38 files changed

+71
-89
lines changed

compiler/rustc_ast/src/ast.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub use UnsafeSource::*;
2727
use crate::ptr::P;
2828
use crate::token::{self, CommentKind, Delimiter};
2929
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
30-
use rustc_data_structures::packed::Pu128;
3130
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3231
use rustc_data_structures::stack::ensure_sufficient_stack;
3332
use rustc_data_structures::sync::Lrc;
@@ -1830,7 +1829,7 @@ pub enum LitKind {
18301829
/// A character literal (`'a'`).
18311830
Char(char),
18321831
/// An integer literal (`1`).
1833-
Int(Pu128, LitIntType),
1832+
Int(u128, LitIntType),
18341833
/// A float literal (`1.0`, `1f64` or `1E10f64`). The pre-suffix part is
18351834
/// stored as a symbol rather than `f64` so that `LitKind` can impl `Eq`
18361835
/// and `Hash`.
@@ -3301,9 +3300,13 @@ mod size_asserts {
33013300
static_assert_size!(Impl, 136);
33023301
static_assert_size!(Item, 136);
33033302
static_assert_size!(ItemKind, 64);
3304-
static_assert_size!(LitKind, 24);
3303+
// This can be removed after i128:128 is in the bootstrap compiler's target.
3304+
#[cfg(not(bootstrap))]
3305+
static_assert_size!(LitKind, 32);
33053306
static_assert_size!(Local, 72);
3306-
static_assert_size!(MetaItemLit, 40);
3307+
// This can be removed after i128:128 is in the bootstrap compiler's target.
3308+
#[cfg(not(bootstrap))]
3309+
static_assert_size!(MetaItemLit, 48);
33073310
static_assert_size!(Param, 40);
33083311
static_assert_size!(Pat, 72);
33093312
static_assert_size!(Path, 24);

compiler/rustc_ast/src/util/literal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ fn integer_lit(symbol: Symbol, suffix: Option<Symbol>) -> Result<LitKind, LitErr
374374
};
375375

376376
let s = &s[if base != 10 { 2 } else { 0 }..];
377-
u128::from_str_radix(s, base).map(|i| LitKind::Int(i.into(), ty)).map_err(|_| {
377+
u128::from_str_radix(s, base).map(|i| LitKind::Int(i, ty)).map_err(|_| {
378378
// Small bases are lexed as if they were base 10, e.g, the string
379379
// might be `0b10201`. This will cause the conversion above to fail,
380380
// but these kinds of errors are already reported by the lexer.

compiler/rustc_ast_lowering/src/expr.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1908,21 +1908,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
19081908
pub(super) fn expr_usize(&mut self, sp: Span, value: usize) -> hir::Expr<'hir> {
19091909
let lit = self.arena.alloc(hir::Lit {
19101910
span: sp,
1911-
node: ast::LitKind::Int(
1912-
(value as u128).into(),
1913-
ast::LitIntType::Unsigned(ast::UintTy::Usize),
1914-
),
1911+
node: ast::LitKind::Int(value as u128, ast::LitIntType::Unsigned(ast::UintTy::Usize)),
19151912
});
19161913
self.expr(sp, hir::ExprKind::Lit(lit))
19171914
}
19181915

19191916
pub(super) fn expr_u32(&mut self, sp: Span, value: u32) -> hir::Expr<'hir> {
19201917
let lit = self.arena.alloc(hir::Lit {
19211918
span: sp,
1922-
node: ast::LitKind::Int(
1923-
u128::from(value).into(),
1924-
ast::LitIntType::Unsigned(ast::UintTy::U32),
1925-
),
1919+
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ast::UintTy::U32)),
19261920
});
19271921
self.expr(sp, hir::ExprKind::Lit(lit))
19281922
}

compiler/rustc_attr/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1185,9 +1185,9 @@ fn allow_unstable<'a>(
11851185

11861186
pub fn parse_alignment(node: &ast::LitKind) -> Result<u32, &'static str> {
11871187
if let ast::LitKind::Int(literal, ast::LitIntType::Unsuffixed) = node {
1188-
if literal.get().is_power_of_two() {
1188+
if literal.is_power_of_two() {
11891189
// rustc_middle::ty::layout::Align restricts align to <= 2^29
1190-
if *literal <= 1 << 29 { Ok(literal.get() as u32) } else { Err("larger than 2^29") }
1190+
if *literal <= 1 << 29 { Ok(*literal as u32) } else { Err("larger than 2^29") }
11911191
} else {
11921192
Err("not a power of two")
11931193
}

compiler/rustc_attr/src/session_diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl<'a> IncorrectReprFormatGenericCause<'a> {
296296
pub fn from_lit_kind(span: Span, kind: &ast::LitKind, name: &'a str) -> Option<Self> {
297297
match kind {
298298
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
299-
Some(Self::Int { span, name, int: int.get() })
299+
Some(Self::Int { span, name, int: *int })
300300
}
301301
ast::LitKind::Str(symbol, _) => Some(Self::Symbol { span, name, symbol: *symbol }),
302302
_ => None,

compiler/rustc_builtin_macros/src/concat_bytes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn invalid_type_err(
5454
val,
5555
ast::LitIntType::Unsuffixed | ast::LitIntType::Unsigned(ast::UintTy::U8),
5656
)) => {
57-
assert!(val.get() > u8::MAX.into()); // must be an error
57+
assert!(val > u8::MAX.into()); // must be an error
5858
dcx.emit_err(ConcatBytesOob { span });
5959
}
6060
Ok(ast::LitKind::Int(_, _)) => {
@@ -86,7 +86,7 @@ fn handle_array_element(
8686
Ok(ast::LitKind::Int(
8787
val,
8888
ast::LitIntType::Unsuffixed | ast::LitIntType::Unsigned(ast::UintTy::U8),
89-
)) if val.get() <= u8::MAX.into() => Some(val.get() as u8),
89+
)) if val <= u8::MAX.into() => Some(val as u8),
9090

9191
Ok(ast::LitKind::Byte(val)) => Some(val),
9292
Ok(ast::LitKind::ByteStr(..)) => {
@@ -148,7 +148,7 @@ pub fn expand_concat_bytes(
148148
if let Some(elem) =
149149
handle_array_element(cx, &mut has_errors, &mut missing_literals, expr)
150150
{
151-
for _ in 0..count_val.get() {
151+
for _ in 0..count_val {
152152
accumulator.push(elem);
153153
}
154154
}

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<u16> {
658658
// if the resulting EXE runs, as I haven't yet built the necessary DLL -- see earlier comment
659659
// about LINK.EXE failing.)
660660
if *ordinal <= u16::MAX as u128 {
661-
Some(ordinal.get() as u16)
661+
Some(*ordinal as u16)
662662
} else {
663663
let msg = format!("ordinal value in `link_ordinal` is too large: `{}`", &ordinal);
664664
tcx.dcx()

compiler/rustc_expand/src/mbe/metavar_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fn parse_depth<'sess>(
124124
};
125125
if let Ok(lit_kind) = LitKind::from_token_lit(*lit)
126126
&& let LitKind::Int(n_u128, LitIntType::Unsuffixed) = lit_kind
127-
&& let Ok(n_usize) = usize::try_from(n_u128.get())
127+
&& let Ok(n_usize) = usize::try_from(n_u128)
128128
{
129129
Ok(n_usize)
130130
} else {

compiler/rustc_hir_typeck/src/expr.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -2982,11 +2982,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29822982
// fixed expression:
29832983
if let ExprKind::Lit(lit) = idx.kind
29842984
&& let ast::LitKind::Int(i, ast::LitIntType::Unsuffixed) = lit.node
2985-
&& i.get()
2986-
< types
2987-
.len()
2988-
.try_into()
2989-
.expect("expected tuple index to be < usize length")
2985+
&& i < types
2986+
.len()
2987+
.try_into()
2988+
.expect("expected tuple index to be < usize length")
29902989
{
29912990
err.span_suggestion(
29922991
brackets_span,

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::ty::TypeAndMut;
1111
use core::cmp::min;
1212
use core::iter;
1313
use rustc_ast::util::parser::{ExprPrecedence, PREC_POSTFIX};
14-
use rustc_data_structures::packed::Pu128;
1514
use rustc_errors::{Applicability, Diagnostic, MultiSpan};
1615
use rustc_hir as hir;
1716
use rustc_hir::def::Res;
@@ -1410,8 +1409,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14101409
}
14111410
let (_, suffix) = snippet.split_at(snippet.len() - 3);
14121411
let value = match suffix {
1413-
"f32" => (lit.get() - 0xf32) / (16 * 16 * 16),
1414-
"f64" => (lit.get() - 0xf64) / (16 * 16 * 16),
1412+
"f32" => (lit - 0xf32) / (16 * 16 * 16),
1413+
"f64" => (lit - 0xf64) / (16 * 16 * 16),
14151414
_ => return false,
14161415
};
14171416
err.span_suggestions(
@@ -1441,8 +1440,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14411440
};
14421441

14431442
// Provided expression needs to be a literal `0`.
1444-
let ExprKind::Lit(Spanned { node: rustc_ast::LitKind::Int(Pu128(0), _), span }) = expr.kind
1445-
else {
1443+
let ExprKind::Lit(Spanned { node: rustc_ast::LitKind::Int(0, _), span }) = expr.kind else {
14461444
return false;
14471445
};
14481446

compiler/rustc_hir_typeck/src/op.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use super::method::MethodCallee;
44
use super::{has_expected_num_generic_args, FnCtxt};
55
use crate::Expectation;
66
use rustc_ast as ast;
7-
use rustc_data_structures::packed::Pu128;
87
use rustc_errors::{struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder};
98
use rustc_hir as hir;
109
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
@@ -835,7 +834,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
835834
hir::Expr {
836835
kind:
837836
hir::ExprKind::Lit(Spanned {
838-
node: ast::LitKind::Int(Pu128(1), _),
837+
node: ast::LitKind::Int(1, _),
839838
..
840839
}),
841840
..

compiler/rustc_lint/src/invalid_from_utf8.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidFromUtf8 {
111111
.map(|e| match &e.kind {
112112
ExprKind::Lit(Spanned { node: lit, .. }) => match lit {
113113
LitKind::Byte(b) => Some(*b),
114-
LitKind::Int(b, _) => Some(b.get() as u8),
114+
LitKind::Int(b, _) => Some(*b as u8),
115115
_ => None,
116116
},
117117
_ => None,

compiler/rustc_lint/src/types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ fn lint_uint_literal<'tcx>(
492492
let lit_val: u128 = match lit.node {
493493
// _v is u8, within range by definition
494494
ast::LitKind::Byte(_v) => return,
495-
ast::LitKind::Int(v, _) => v.get(),
495+
ast::LitKind::Int(v, _) => v,
496496
_ => bug!(),
497497
};
498498
if lit_val < min || lit_val > max {
@@ -555,7 +555,7 @@ fn lint_literal<'tcx>(
555555
ty::Int(t) => {
556556
match lit.node {
557557
ast::LitKind::Int(v, ast::LitIntType::Signed(_) | ast::LitIntType::Unsuffixed) => {
558-
lint_int_literal(cx, type_limits, e, lit, t, v.get())
558+
lint_int_literal(cx, type_limits, e, lit, t, v)
559559
}
560560
_ => bug!(),
561561
};
@@ -842,7 +842,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
842842
ast::LitKind::Int(
843843
v,
844844
ast::LitIntType::Signed(_) | ast::LitIntType::Unsuffixed,
845-
) => v.get() as i128,
845+
) => v as i128,
846846
_ => return true,
847847
},
848848
_ => bug!(),
@@ -853,7 +853,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
853853
let (min, max): (u128, u128) = uint_ty_range(uint_ty);
854854
let lit_val: u128 = match lit.kind {
855855
hir::ExprKind::Lit(li) => match li.node {
856-
ast::LitKind::Int(v, _) => v.get(),
856+
ast::LitKind::Int(v, _) => v,
857857
_ => return true,
858858
},
859859
_ => bug!(),

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ impl<'tcx> TyCtxt<'tcx> {
745745
],
746746
) = attr.meta_item_list().as_deref()
747747
{
748-
Bound::Included(a.get())
748+
Bound::Included(a)
749749
} else {
750750
self.dcx().span_delayed_bug(
751751
attr.span,

compiler/rustc_mir_build/src/build/expr/as_constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn lit_to_mir_constant<'tcx>(
153153
ConstValue::Scalar(Scalar::from_uint(*n, Size::from_bytes(1)))
154154
}
155155
(ast::LitKind::Int(n, _), ty::Uint(_)) | (ast::LitKind::Int(n, _), ty::Int(_)) => {
156-
trunc(if neg { (n.get() as i128).overflowing_neg().0 as u128 } else { n.get() })?
156+
trunc(if neg { (*n as i128).overflowing_neg().0 as u128 } else { *n })?
157157
}
158158
(ast::LitKind::Float(n, _), ty::Float(fty)) => parse_float_into_constval(*n, *fty, neg)
159159
.ok_or_else(|| {

compiler/rustc_mir_build/src/thir/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub(crate) fn lit_to_const<'tcx>(
5454
}
5555
(ast::LitKind::Int(n, _), ty::Uint(_)) | (ast::LitKind::Int(n, _), ty::Int(_)) => {
5656
let scalar_int =
57-
trunc(if neg { (n.get() as i128).overflowing_neg().0 as u128 } else { n.get() })?;
57+
trunc(if neg { (*n as i128).overflowing_neg().0 as u128 } else { *n })?;
5858
ty::ValTree::from_scalar_int(scalar_int)
5959
}
6060
(ast::LitKind::Bool(b), ty::Bool) => ty::ValTree::from_scalar_int((*b).into()),

compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
20692069
let mut ret = Vec::new();
20702070
for meta in attr.meta_item_list()? {
20712071
match meta.lit()?.kind {
2072-
LitKind::Int(a, _) => ret.push(a.get() as usize),
2072+
LitKind::Int(a, _) => ret.push(a as usize),
20732073
_ => panic!("invalid arg index"),
20742074
}
20752075
}

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[ast::Attrib
10491049
func.decl
10501050
.inputs
10511051
.values
1052-
.insert(a.get() as _, Argument { name, type_: *ty, is_const: true });
1052+
.insert(a as _, Argument { name, type_: *ty, is_const: true });
10531053
} else {
10541054
panic!("unexpected non const in position {pos}");
10551055
}

src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs

+1-1
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.get().leading_zeros()
110+
&& let from_nbits = 128 - n.leading_zeros()
111111
&& let to_nbits = fp_ty_mantissa_nbits(cast_to)
112112
&& from_nbits != 0
113113
&& to_nbits != 0

src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ 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;
76
use rustc_errors::Applicability;
87
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind};
98
use rustc_lint::{LateContext, LateLintPass};
@@ -70,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd {
7069
&& clippy_utils::SpanlessEq::new(cx).eq_expr(l, target)
7170
&& BinOpKind::Add == op1.node
7271
&& let ExprKind::Lit(lit) = value.kind
73-
&& let LitKind::Int(Pu128(1), LitIntType::Unsuffixed) = lit.node
72+
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
7473
&& block.expr.is_none()
7574
{
7675
let mut app = Applicability::MachineApplicable;

src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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;
54
use rustc_errors::Applicability;
65
use rustc_hir::{BinOpKind, Expr, ExprKind, QPath};
76
use rustc_lint::{LateContext, LateLintPass};
@@ -87,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
8786
match cond_num_val.kind {
8887
ExprKind::Lit(cond_lit) => {
8988
// Check if the constant is zero
90-
if let LitKind::Int(Pu128(0), _) = cond_lit.node {
89+
if let LitKind::Int(0, _) = cond_lit.node {
9190
if cx.typeck_results().expr_ty(cond_left).is_signed() {
9291
} else {
9392
print_lint_and_sugg(cx, var_name, expr);

src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs

+1-1
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.get())
464+
Some(value)
465465
} else {
466466
None
467467
}

src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs

+2-2
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.get() + 1 >= arr_len.into(),
213-
ast::RangeLimits::HalfOpen => end_int.get() >= arr_len.into(),
212+
ast::RangeLimits::Closed => end_int + 1 >= arr_len.into(),
213+
ast::RangeLimits::HalfOpen => end_int >= arr_len.into(),
214214
};
215215
}
216216

src/tools/clippy/clippy_lints/src/manual_bits.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ 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;
76
use rustc_errors::Applicability;
87
use rustc_hir::{BinOpKind, Expr, ExprKind, GenericArg, QPath};
98
use rustc_lint::{LateContext, LateLintPass, LintContext};
@@ -63,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualBits {
6362
&& let Some((real_ty, resolved_ty, other_expr)) = get_one_size_of_ty(cx, left_expr, right_expr)
6463
&& matches!(resolved_ty.kind(), ty::Int(_) | ty::Uint(_))
6564
&& let ExprKind::Lit(lit) = &other_expr.kind
66-
&& let LitKind::Int(Pu128(8), _) = lit.node
65+
&& let LitKind::Int(8, _) = lit.node
6766
{
6867
let mut app = Applicability::MachineApplicable;
6968
let ty_snip = snippet_with_context(cx, real_ty.span, ctxt, "..", &mut app).0;

src/tools/clippy/clippy_lints/src/manual_range_patterns.rs

+1-1
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.get().try_into().ok()
48+
num.try_into().ok()
4949
} else {
5050
None
5151
}

src/tools/clippy/clippy_lints/src/manual_strip.rs

+1-1
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| *n == length)
164+
constant_length(cx, pattern).map_or(false, |length| length == *n)
165165
} else {
166166
len_arg(cx, expr).map_or(false, |arg| eq_expr_value(cx, pattern, arg))
167167
}

0 commit comments

Comments
 (0)