Skip to content

Commit 2aaaeb4

Browse files
committed
use AllocId instead of Allocation in ConstValue::ByRef
1 parent 0698591 commit 2aaaeb4

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

clippy_utils/src/consts.rs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -684,34 +684,37 @@ pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'t
684684
},
685685
_ => None,
686686
},
687-
mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() {
688-
ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)),
689-
ty::Array(sub_type, len) => match sub_type.kind() {
690-
ty::Float(FloatTy::F32) => match len.try_to_target_usize(lcx.tcx) {
691-
Some(len) => alloc
692-
.inner()
693-
.inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * usize::try_from(len).unwrap()))
694-
.to_owned()
695-
.array_chunks::<4>()
696-
.map(|&chunk| Some(Constant::F32(f32::from_le_bytes(chunk))))
697-
.collect::<Option<Vec<Constant<'tcx>>>>()
698-
.map(Constant::Vec),
699-
_ => None,
700-
},
701-
ty::Float(FloatTy::F64) => match len.try_to_target_usize(lcx.tcx) {
702-
Some(len) => alloc
703-
.inner()
704-
.inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * usize::try_from(len).unwrap()))
705-
.to_owned()
706-
.array_chunks::<8>()
707-
.map(|&chunk| Some(Constant::F64(f64::from_le_bytes(chunk))))
708-
.collect::<Option<Vec<Constant<'tcx>>>>()
709-
.map(Constant::Vec),
687+
mir::ConstantKind::Val(ConstValue::ByRef { alloc_id, offset: _ }, _) => {
688+
let alloc = lcx.tcx.global_alloc(alloc_id).unwrap_memory();
689+
match result.ty().kind() {
690+
ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)),
691+
ty::Array(sub_type, len) => match sub_type.kind() {
692+
ty::Float(FloatTy::F32) => match len.try_to_target_usize(lcx.tcx) {
693+
Some(len) => alloc
694+
.inner()
695+
.inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * usize::try_from(len).unwrap()))
696+
.to_owned()
697+
.array_chunks::<4>()
698+
.map(|&chunk| Some(Constant::F32(f32::from_le_bytes(chunk))))
699+
.collect::<Option<Vec<Constant<'tcx>>>>()
700+
.map(Constant::Vec),
701+
_ => None,
702+
},
703+
ty::Float(FloatTy::F64) => match len.try_to_target_usize(lcx.tcx) {
704+
Some(len) => alloc
705+
.inner()
706+
.inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * usize::try_from(len).unwrap()))
707+
.to_owned()
708+
.array_chunks::<8>()
709+
.map(|&chunk| Some(Constant::F64(f64::from_le_bytes(chunk))))
710+
.collect::<Option<Vec<Constant<'tcx>>>>()
711+
.map(Constant::Vec),
712+
_ => None,
713+
},
710714
_ => None,
711715
},
712716
_ => None,
713-
},
714-
_ => None,
717+
}
715718
},
716719
_ => None,
717720
}

0 commit comments

Comments
 (0)