Skip to content

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

Closed
@eddyb

Description

@eddyb

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

Metadata

Metadata

Assignees

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-destructorsArea: Destructors (`Drop`, …)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions