Skip to content
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

Closed
alexcrichton opened this Issue Jul 30, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@alexcrichton
Copy link
Member

alexcrichton commented Jul 30, 2015

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:

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(&mut cnt);
        if i == 1 {
            break
        }
        drop(a);
    }
    assert_eq!(cnt, 2);
}

cc @pnkfelix

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Jul 30, 2015

Interestingly this slight variation on the above code does drop twice as expected:

playpen

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

Reinitialize the dropflag hint in binding occurrences.
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

Auto merge of #27413 - pnkfelix:fix-issue-27401, r=nikomatsakis
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.

bors added a commit that referenced this issue Jul 31, 2015

Auto merge of #27413 - pnkfelix:fix-issue-27401, r=nikomatsakis
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

bors added a commit that referenced this issue Aug 7, 2015

Auto merge of #27582 - pnkfelix:disable-nonzeroing-move-hint-by-defau…
…lt, r=nikomatsakis

Turn nonzeroing move hints back off by default.

Works around bugs injected by PR #26173.

 * (@pnkfelix is unavailable in the short-term (i.e. for the next week) to fix them.)

 * When the bugs are fixed, we will turn nonzeroing move hints back on by default.

Fix #27401

bors added a commit that referenced this issue Aug 7, 2015

Auto merge of #27582 - pnkfelix:disable-nonzeroing-move-hint-by-defau…
…lt, r=nikomatsakis

Turn nonzeroing move hints back off by default.

Works around bugs injected by PR #26173.

 * (@pnkfelix is unavailable in the short-term (i.e. for the next week) to fix them.)

 * When the bugs are fixed, we will turn nonzeroing move hints back on by default.

Fix #27401

@bors bors closed this in #27582 Aug 7, 2015

brson added a commit to brson/rust that referenced this issue Aug 10, 2015

sfackler added 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

Reinitialize the dropflag hint in binding occurrences.
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
You can’t perform that action at this time.