move
move copied to clipboard
[Bug] ICE invalid assign tmp local
struct Foo {
a: u64,
}
#[test]
fun ice() {
use Std::Vector;
let v = Vector::empty();
Vector::push_back(&mut v, Foo {a: 10});
let b = Vector::borrow(&v, 0);
while (true) {
b = &Vector::pop_back(&mut v);
let Foo {a: _} = *b;
};
Vector::destroy_empty(v);
}
this piece of code caused "ICE invalid assign tmp local"
Ah yes this one again... Should really give a better error message as I don't htink we will fix the underlying issue anytime soon
So what is the issue and what is the workaround?
No real workaround, if you expanded this to locals instead of temps, you will still get a borrow checker issue.
The minimal repro is
while (cond) {
let tmp = e;
let b = &tmp;
... use b ...
}
In the borrow checker, first time through the loop:
while (cond) {
let tmp = e; // assignment okay
let b = &tmp; // b = { &tmp }
... use b ...
}
Second time through the loop
while (cond) {
let tmp = e; // ERROR assignment invalid! 'tmp' is still borrowed by 'b'!
let b = &tmp; // b = { &tmp }
... use b ...
}
The error message just assumed this couldn't happen with a local variable created by the compiler, which happens if you make this example into:
while (cond) {
let b = &e;
... use b ...
}
You cannot borrow values on the stack in Move, so e gets bound to some local variable. and then the example is equivalent to the first one.
I think we just need a proper error message instead of ICE for now
I think we just need a proper error message instead of ICE for now And line / column of the issue? (IIUC currently we don't have them)