Skip to content

Commit 96eb116

Browse files
committed
Introduce ConstAllocation.
Currently some `Allocation`s are interned, some are not, and it's very hard to tell at a use point which is which. This commit introduces `ConstAllocation` for the known-interned ones, which makes the division much clearer. `ConstAllocation::inner()` is used to get the underlying `Allocation`. In some places it's natural to use an `Allocation`, in some it's natural to use a `ConstAllocation`, and in some places there's no clear choice. I've tried to make things look as nice as possible, while generally favouring `ConstAllocation`, which is the type that embodies more information. This does require quite a few calls to `inner()`. The commit also tweaks how `PartialOrd` works for `Interned`. The previous code was too clever by half, building on `T: Ord` to make the code shorter. That caused problems with deriving `PartialOrd` and `Ord` for `ConstAllocation`, so I changed it to build on `T: PartialOrd`, which is slightly more verbose but much more standard and avoided the problems.
1 parent dcc6ecf commit 96eb116

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

clippy_utils/src/consts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ pub fn miri_to_const(result: ty::Const<'_>) -> Option<Constant> {
593593
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(
596-
data.inspect_with_uninit_and_ptr_outside_interpreter(start..end)
596+
data.inner().inspect_with_uninit_and_ptr_outside_interpreter(start..end)
597597
.to_owned(),
598598
)
599599
.ok()
@@ -605,7 +605,7 @@ pub fn miri_to_const(result: ty::Const<'_>) -> Option<Constant> {
605605
ty::ConstKind::Value(ConstValue::ByRef { alloc, offset: _ }) => match result.ty().kind() {
606606
ty::Array(sub_type, len) => match sub_type.kind() {
607607
ty::Float(FloatTy::F32) => match miri_to_const(*len) {
608-
Some(Constant::Int(len)) => alloc
608+
Some(Constant::Int(len)) => alloc.inner()
609609
.inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize))
610610
.to_owned()
611611
.chunks(4)
@@ -619,7 +619,7 @@ pub fn miri_to_const(result: ty::Const<'_>) -> Option<Constant> {
619619
_ => None,
620620
},
621621
ty::Float(FloatTy::F64) => match miri_to_const(*len) {
622-
Some(Constant::Int(len)) => alloc
622+
Some(Constant::Int(len)) => alloc.inner()
623623
.inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * len as usize))
624624
.to_owned()
625625
.chunks(8)

0 commit comments

Comments
 (0)