Skip to content

Commit 64ae3ae

Browse files
committed
Overhaul Const.
Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as this: ``` pub struct Const<'tcx>(&'tcx Interned<ConstS>); ``` This now matches `Ty` and `Predicate` more closely, including using pointer-based `eq` and `hash`. Notable changes: - `mk_const` now takes a `ConstS`. - `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a we need separate arena for it, because we can't use the `Dropless` one any more. - Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes - Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes. - Lots of tedious sigil fiddling.
1 parent d071ce1 commit 64ae3ae

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

clippy_lints/src/large_const_arrays.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
5353
if let ItemKind::Const(hir_ty, _) = &item.kind;
5454
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
5555
if let ty::Array(element_type, cst) = ty.kind();
56-
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val;
56+
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val();
5757
if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
5858
if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes());
5959
if self.maximum_allowed_size < element_count * element_size;

clippy_lints/src/large_stack_arrays.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays {
4343
if_chain! {
4444
if let ExprKind::Repeat(_, _) = expr.kind;
4545
if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind();
46-
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val;
46+
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val();
4747
if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
4848
if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes());
4949
if self.maximum_allowed_size < element_count * element_size;

clippy_lints/src/non_copy_const.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ fn is_value_unfrozen_raw<'tcx>(
136136
result: Result<ConstValue<'tcx>, ErrorHandled>,
137137
ty: Ty<'tcx>,
138138
) -> bool {
139-
fn inner<'tcx>(cx: &LateContext<'tcx>, val: &'tcx Const<'tcx>) -> bool {
140-
match val.ty.kind() {
139+
fn inner<'tcx>(cx: &LateContext<'tcx>, val: Const<'tcx>) -> bool {
140+
match val.ty().kind() {
141141
// the fact that we have to dig into every structs to search enums
142142
// leads us to the point checking `UnsafeCell` directly is the only option.
143143
ty::Adt(ty_def, ..) if Some(ty_def.did) == cx.tcx.lang_items().unsafe_cell_type() => true,
144144
ty::Array(..) | ty::Adt(..) | ty::Tuple(..) => {
145145
let val = cx.tcx.destructure_const(cx.param_env.and(val));
146-
val.fields.iter().any(|field| inner(cx, field))
146+
val.fields.iter().any(|field| inner(cx, *field))
147147
},
148148
_ => false,
149149
}

clippy_utils/src/consts.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,11 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
567567
}
568568
}
569569

570-
pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
570+
pub fn miri_to_const(result: ty::Const<'_>) -> Option<Constant> {
571571
use rustc_middle::mir::interpret::ConstValue;
572-
match result.val {
572+
match result.val() {
573573
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int(int))) => {
574-
match result.ty.kind() {
574+
match result.ty().kind() {
575575
ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)),
576576
ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.assert_bits(int.size()))),
577577
ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits(
@@ -590,7 +590,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
590590
_ => None,
591591
}
592592
},
593-
ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty.kind() {
593+
ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty().kind() {
594594
ty::Ref(_, tam, _) => match tam.kind() {
595595
ty::Str => String::from_utf8(
596596
data.inspect_with_uninit_and_ptr_outside_interpreter(start..end)
@@ -602,9 +602,9 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
602602
},
603603
_ => None,
604604
},
605-
ty::ConstKind::Value(ConstValue::ByRef { alloc, offset: _ }) => match result.ty.kind() {
605+
ty::ConstKind::Value(ConstValue::ByRef { alloc, offset: _ }) => match result.ty().kind() {
606606
ty::Array(sub_type, len) => match sub_type.kind() {
607-
ty::Float(FloatTy::F32) => match miri_to_const(len) {
607+
ty::Float(FloatTy::F32) => match miri_to_const(*len) {
608608
Some(Constant::Int(len)) => alloc
609609
.inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize))
610610
.to_owned()
@@ -618,7 +618,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
618618
.map(Constant::Vec),
619619
_ => None,
620620
},
621-
ty::Float(FloatTy::F64) => match miri_to_const(len) {
621+
ty::Float(FloatTy::F64) => match miri_to_const(*len) {
622622
Some(Constant::Int(len)) => alloc
623623
.inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * len as usize))
624624
.to_owned()

0 commit comments

Comments
 (0)