Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Move out of reference in move closures #31

Closed
rust-lang/rust
#82007
@arora-aman

Description

@arora-aman
struct S {
    x: String,
    y: String
}

fn x(s: &mut S) {
    let mut c = move || {
        s.x.truncate(0);
    };
    c();
}


fn main() {
    let mut s = S { x: "".into(), y: "".into() };
    x(&mut s);
}

Without the feature gate s which is a &mut S is moved. However with the feature gate *s.x is moved which is a String which behind a &mut S and can't be moved out.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions