flux
flux copied to clipboard
Panic when dropping and replacing value through a mutable reference
The following code panic when trying to update centers[i]
#[flux::sig(fn(&RVec<f32>[@n], usize) -> RVec<f32>[n])]
fn normal(x: &RVec<f32>, w: usize) -> RVec<f32> {
let mut i = 0;
let mut res = RVec::new();
while i < x.len() {
res.push(x[i] / (w as f32));
i += 1;
}
res
}
#[flux::sig(fn (n: usize, centers: &mut RVec<RVec<f32>[n]>[@k], new_centers: RVec<(usize, (RVec<f32>, usize))>))]
fn update_centers(
n: usize,
centers: &mut RVec<RVec<f32>>,
new_centers: RVec<(usize, (RVec<f32>, usize))>,
) {
for (i, (x, size)) in new_centers {
centers[i] = normal(&x, size)
}
}
This is the panic
error: internal compiler error: flux-refineck/src/type_env.rs:169:17: cannot move out of `*_21`, which is behind a `&mut` reference
--> /home/nlehmann/phd/flux-rs/flux/attic/playground.rs:24:9
|
24 | centers[i] = normal(&x, size)
| ^^^^^^^^^^
-Ztrack-diagnostics: created at /rustc/700938c0781c9f135244bb1ec846fe1a5e03ae7d/compiler/rustc_errors/src/lib.rs:995:33