Support partial moves on enum destructuring

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
    let Struct { b, .. } = the_struct;

    // Enums will be moved as a whole
    enum Enum {

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

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

    // Do something that makes match inconvinient

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

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.


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