-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drop flags on the stack not reinitialized in loops #27401
Labels
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
Interestingly this slight variation on the above code does drop twice as expected: struct A<'a>(&'a mut i32);
impl<'a> Drop for A<'a> {
fn drop(&mut self) {
*self.0 += 1;
}
}
fn main() {
let mut cnt = 0;
for i in 0..2 {
let a; a = A(&mut cnt); // This was `let a = A(&mut cnt);` before
if i == 1 {
break
}
drop(a);
}
assert_eq!(cnt, 2);
} |
pnkfelix
added a commit
to pnkfelix/rust
that referenced
this issue
Jul 31, 2015
Such bindings can occur in loops, and thus the binding can be executed after a previous move cleared the flag, thus necessitating the flag be reset to `DTOR_NEEDED_HINT`. Fix rust-lang#27401.
pnkfelix
added a commit
to pnkfelix/rust
that referenced
this issue
Jul 31, 2015
bors
added a commit
that referenced
this issue
Jul 31, 2015
Reinitialize the dropflag hint in occurrences of variable bindings. Such bindings can occur in loops, and thus the binding can be executed after a previous move cleared the flag, thus necessitating the flag be reset to `DTOR_NEEDED_HINT`. Fix #27401.
pnkfelix
added a commit
to pnkfelix/rust
that referenced
this issue
Aug 7, 2015
brson
pushed a commit
to brson/rust
that referenced
this issue
Aug 10, 2015
sfackler
pushed a commit
to sfackler/rust
that referenced
this issue
Aug 11, 2015
pnkfelix
added a commit
to pnkfelix/rust
that referenced
this issue
Aug 19, 2015
Such bindings can occur in loops, and thus the binding can be executed after a previous move cleared the flag, thus necessitating the flag be reset to `DTOR_NEEDED_HINT`. Fix rust-lang#27401.
pnkfelix
added a commit
to pnkfelix/rust
that referenced
this issue
Aug 19, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like that when a local variable is initialized in a loop and dropped in the same loop, the stack local drop flag for that local isn't reinitialized to "not dropped" when the loop runs after the first time.
Concretely, this test passes on stable and fails on nightly right now:
cc @pnkfelix
The text was updated successfully, but these errors were encountered: