# Support partial moves on enum destructuring

**URL:** <https://internals.rust-lang.org/t/support-partial-moves-on-enum-destructuring/19791>\
**Category:** language design\
**Created:** [October 31, 2023, 3:10pm UTC](https://internals.rust-lang.org/t/support-partial-moves-on-enum-destructuring/19791 "2023-10-31T15:10:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ModProg](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/modprog/32/11293_2.png) [@ModProg](https://internals.rust-lang.org/u/ModProg)\
**Post date:** [October 31, 2023, 3:10pm UTC](https://internals.rust-lang.org/t/support-partial-moves-on-enum-destructuring/19791/1 "2023-10-31T15:10:59Z")

</div>

```rs
fn main() {
    // Structs allow moving fields individually
    struct Struct {
        a: String,
        b: String,
    }
    let the_struct = Struct {
        a: "hello".into(),
        b: "hi".into(),
    };
    // both field access and destructuring only move the referenced fields
    drop(the_struct.a);
    let Struct { b, .. } = the_struct;
    drop(b);

    // Enums will be moved as a whole
    enum Enum {
        A(String),
        B(String),
    }

    let the_enum = Enum::A("hello".into());

    // IMO only A should be moved
    if let Enum::A(a) = the_enum {
        drop(a);
    }

    // Do something that makes match inconvinient

    // B variant cannot be accessed
    if let Enum::B(b) = the_enum {}
}

```

---

<div class="post-metadata">

**Author:** ![jdahlstrom](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jdahlstrom/32/3351_2.png) [@jdahlstrom](https://internals.rust-lang.org/u/jdahlstrom)\
**Post date:** [October 31, 2023, 4:31pm UTC](https://internals.rust-lang.org/t/support-partial-moves-on-enum-destructuring/19791/2 "2023-10-31T16:31:50Z")

</div>

I think this is a known limitation in the current borrow checker, it’s not as much about partial borrows but following control flow and reasoning about two different worlds (the one where the enum was an A, vs the one where it was a B). The original borrock was strictly lexical (based on literal textual scopes), and the current one is more permissive but still forbids a lot of valid code. But the next generation has been in the works for a while.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [January 29, 2024, 4:32pm UTC](https://internals.rust-lang.org/t/support-partial-moves-on-enum-destructuring/19791/3 "2024-01-29T16:32:27Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
