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

Bogus "warning: dataflow bug??? moving out of type with dtor" for field assignments. #34101

Closed
eddyb opened this issue Jun 5, 2016 · 5 comments
Assignees
Labels
A-destructors Area: destructors (Drop, ..) A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html

Comments

@eddyb
Copy link
Member

eddyb commented Jun 5, 2016

When assigning a non-Copy field of a structure which has a destructor, the drop of the field before writing the new value causes a warning in the MIR dataflow code:

struct Foo(String);

impl Drop for Foo {
    fn drop(&mut self) {}
}

fn main() {
    let mut f = Foo(String::from("foo"));
    f.0 = String::from("bar");
}
test.rs:8:9: 8:14 warning: dataflow bug??? moving out of type with dtor DropCtxt { span: test.rs:8:9: 8:14, scope: ScopeId(3), is_cleanup: true, init_data: , lvalue: var0, path: MovePathIndex(NonZero(1)), succ: bb1, unwind: None }
test.rs:8     let mut f = Foo(String::from("foo"));
                  ^~~~~

Seeing how this is supported in stable Rust, the warning seems superfluous and the resulting code runs without a hitch, although I'm not sure if there any subtle problems around unwinding.

cc @arielb1 @pnkfelix

@eddyb eddyb added the A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html label Jun 5, 2016
@nikomatsakis
Copy link
Contributor

cc me

@pnkfelix pnkfelix self-assigned this Jun 6, 2016
@pnkfelix pnkfelix added the A-destructors Area: destructors (Drop, ..) label Jun 6, 2016
@pnkfelix
Copy link
Member

pnkfelix commented Jun 6, 2016

My current intuition is that the gather_moves pass on DropAndReplace on a Projection (e.g. var0.0 here) on its own is creating a separate MovePath for the replaced thing, but maybe we should not do this, since it is causing us to allocate a separate drop flag for var0.0 even though such a flag can never have a state distinct from the state for the drop flag for var0 itself.

Update: Then again, maybe its simpler to leave gather_moves alone; otherwise it seems like gather_moves would need to deal with conditionally looking up the MovePath in question depending on whether code elsewhere had created one... (or alternatively, gather_moves could solely filter out creating a MovePath when some parent path has a destructor attached).

@pnkfelix
Copy link
Member

pnkfelix commented Jun 6, 2016

Or maybe the right approach, which has the advantage of being isolated to elaborate_drops, would be to change lvalue_contents_are_tracked to return false when the parent lvalue's type has a Drop impl.

@pnkfelix
Copy link
Member

pnkfelix commented Jun 6, 2016

(I have a patch for this, I'll put up a PR shortly.)

pnkfelix added a commit to pnkfelix/rust that referenced this issue Jun 7, 2016
…nor gather flags for untracked content.

(Includes a regression test, which needed to go into `compile-fail/`
due to weaknesses when combining `#[deny(warnings)]` with
`tcx.sess.span_warn(..)`)

(updated with review feedback from arielb1.)
Manishearth added a commit to Manishearth/rust that referenced this issue Jun 8, 2016
Fix issue rust-lang#34101

Fix issue rust-lang#34101: do not track subcontent of type with dtor nor gather flags for untracked content.

(Includes a regression test, which needed to go into `compile-fail/`
due to weaknesses when combining `#[deny(warnings)]` with
`tcx.sess.span_warn(..)`)
bors added a commit that referenced this issue Jun 9, 2016
Fix issue #34101

Fix issue #34101: do not track subcontent of type with dtor nor gather flags for untracked content.

(Includes a regression test, which needed to go into `compile-fail/`
due to weaknesses when combining `#[deny(warnings)]` with
`tcx.sess.span_warn(..)`)
@pnkfelix
Copy link
Member

Fixed by PR #34109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-destructors Area: destructors (Drop, ..) A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
Projects
None yet
Development

No branches or pull requests

3 participants