Skip to content

Commit 021802c

Browse files
committed
Support enum in memory map patch address
1 parent 31c3093 commit 021802c

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

crates/hir-ty/src/consteval/tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2441,14 +2441,14 @@ fn const_loop() {
24412441
fn const_transfer_memory() {
24422442
check_number(
24432443
r#"
2444-
//- minicore: slice, index, coerce_unsized
2444+
//- minicore: slice, index, coerce_unsized, option
24452445
const A1: &i32 = &1;
24462446
const A2: &i32 = &10;
24472447
const A3: [&i32; 3] = [&1, &2, &100];
2448-
const A4: (i32, &i32) = (1, &1000);
2449-
const GOAL: i32 = *A1 + *A2 + *A3[2] + *A4.1;
2448+
const A4: (i32, &i32, Option<&i32>) = (1, &1000, Some(&10000));
2449+
const GOAL: i32 = *A1 + *A2 + *A3[2] + *A4.1 + *A4.2.unwrap_or(&5);
24502450
"#,
2451-
1111,
2451+
11111,
24522452
);
24532453
}
24542454

crates/hir-ty/src/mir/eval.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,28 @@ impl Evaluator<'_> {
20072007
}
20082008
}
20092009
AdtId::UnionId(_) => (),
2010-
AdtId::EnumId(_) => (),
2010+
AdtId::EnumId(e) => {
2011+
if let Some((variant, layout)) = detect_variant_from_bytes(
2012+
&layout,
2013+
self.db,
2014+
self.trait_env.clone(),
2015+
self.read_memory(addr, layout.size.bytes_usize())?,
2016+
e,
2017+
) {
2018+
let ev = EnumVariantId { parent: e, local_id: variant };
2019+
for (i, (_, ty)) in self.db.field_types(ev.into()).iter().enumerate() {
2020+
let offset = layout.fields.offset(i).bytes_usize();
2021+
let ty = ty.clone().substitute(Interner, subst);
2022+
self.patch_addresses(
2023+
patch_map,
2024+
old_vtable,
2025+
addr.offset(offset),
2026+
&ty,
2027+
locals,
2028+
)?;
2029+
}
2030+
}
2031+
}
20112032
},
20122033
TyKind::Tuple(_, subst) => {
20132034
for (id, ty) in subst.iter(Interner).enumerate() {

0 commit comments

Comments
 (0)