You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code segfaults in both 0.6 and the current incoming:
struct A { t: bool }
fn main() {
let mut a = ~A { t: false };
let f = || { a.t = true; };
let mut x = a;
f();
x.t = false; // not strictly required but ignores an warning
}
The cause is that a was moved to x and f (created before the movement) was unable to deduce that a has been moved. Ideally such code should not compile.
The text was updated successfully, but these errors were encountered:
Hmm, it seems that because f is a stack closure, it is allowed to capture upvars pretty much without limit, because (it thinks) it can guarantee that the captured variables are valid for it's lifetime. Ideally, it should act as if the closure either has a mutable borrow, or that a has been moved. I'm tempted to lean towards the first option in this case, since it means that the end of f releases the borrow, thus allowing a to be used again.
This means that this code shouldn't compile, giving the same error message as:
fnmain(){letmut a = ~1;let b = &mut*a;
a = ~2;}// error: cannot assign to `a` because it is borrowed
The following code segfaults in both 0.6 and the current incoming:
The cause is that
a
was moved tox
andf
(created before the movement) was unable to deduce thata
has been moved. Ideally such code should not compile.The text was updated successfully, but these errors were encountered: