Skip to content

Commit 2cce657

Browse files
Merge pull request #22030 from Wilfred/pre-mir-relocation-test
fix: MIR evaluation of sized &T with recursive const fn
2 parents 8e2d2ad + 869fd7e commit 2cce657

2 files changed

Lines changed: 70 additions & 7 deletions

File tree

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,10 +2211,10 @@ impl<'db> Evaluator<'db> {
22112211
match size {
22122212
Some((size, _)) => {
22132213
let addr_usize = from_bytes!(usize, bytes);
2214-
mm.insert(
2215-
addr_usize,
2216-
this.read_memory(Address::from_usize(addr_usize), size)?.into(),
2217-
)
2214+
let bytes =
2215+
this.read_memory(Address::from_usize(addr_usize), size)?.to_vec();
2216+
mm.insert(addr_usize, bytes.clone().into());
2217+
rec(this, &bytes, t, locals, mm, stack_depth_limit - 1)?;
22182218
}
22192219
None => {
22202220
let mut check_inner = None;
@@ -2379,9 +2379,20 @@ impl<'db> Evaluator<'db> {
23792379
match size {
23802380
Some(_) => {
23812381
let current = from_bytes!(usize, self.read_memory(addr, my_size)?);
2382-
if let Some(it) = patch_map.get(&current) {
2383-
self.write_memory(addr, &it.to_le_bytes())?;
2384-
}
2382+
let patched = match patch_map.get(&current) {
2383+
Some(it) => {
2384+
self.write_memory(addr, &it.to_le_bytes())?;
2385+
*it
2386+
}
2387+
None => current,
2388+
};
2389+
self.patch_addresses(
2390+
patch_map,
2391+
ty_of_bytes,
2392+
Address::from_usize(patched),
2393+
t,
2394+
locals,
2395+
)?;
23852396
}
23862397
None => {
23872398
let current = from_bytes!(usize, self.read_memory(addr, my_size / 2)?);

crates/ide/src/hover/tests.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11078,6 +11078,58 @@ impl PublicFlags for NoteDialects {
1107811078
);
1107911079
}
1108011080

11081+
#[test]
11082+
fn hover_recursive_const_fn() {
11083+
check(
11084+
r#"
11085+
//- minicore: option
11086+
enum Child {
11087+
Static { child: &'static MyEnum },
11088+
}
11089+
11090+
enum MyEnum {
11091+
Unit,
11092+
Array(Child),
11093+
}
11094+
11095+
impl MyEnum {
11096+
pub const fn static_array(child: &'static MyEnum) -> Self {
11097+
MyEnum::Array(Child::Static { child })
11098+
}
11099+
}
11100+
11101+
pub trait MyTrait {
11102+
const MY_CONST: &'static MyEnum;
11103+
}
11104+
11105+
impl<T> MyTrait for Option<T> where T: MyTrait {
11106+
const MY_CONST: &'static MyEnum = &MyEnum::static_array(T::MY_CONST);
11107+
}
11108+
11109+
impl MyTrait for () {
11110+
const MY_CONST: &'static MyEnum = &MyEnum::Unit;
11111+
}
11112+
11113+
pub struct Address;
11114+
11115+
impl MyTrait for Address {
11116+
const MY_CONST$0: &'static MyEnum = (<Option<()> as MyTrait>::MY_CONST);
11117+
}
11118+
"#,
11119+
expect![[r#"
11120+
*MY_CONST*
11121+
11122+
```rust
11123+
ra_test_fixture::Address
11124+
```
11125+
11126+
```rust
11127+
const MY_CONST: &'static MyEnum = &Array(Static { child: &Unit })
11128+
```
11129+
"#]],
11130+
);
11131+
}
11132+
1108111133
#[test]
1108211134
fn bounds_from_container_do_not_panic() {
1108311135
check(

0 commit comments

Comments
 (0)