Skip to content

Dereferencing boxed tuple doesn't compile properly. #30564

Closed
@Mokosha

Description

@Mokosha

I think I've encountered a bug, as was described in this stack overflow question. In particular, I would expect the syntax in the following code to be allowed:

#[derive(Clone, PartialEq, Debug)]
enum Foo {
  Base,
  Branch(Box<(Foo, Foo)>)
}

fn do_something(f: Foo) -> Foo {
  match f {
    Foo::Base => Foo::Base,
    Foo::Branch(pair) => {
      let (f1, f2) = *pair;  // ... What do I do here?
      if f2 == Foo::Base { f1 } else { f2 }
   }
  }
}

fn main() {
  let foo = Foo::Base;
  println!("Foo: {:?}", do_something(foo));
}

Instead, I need to do something like

let p = *pair;
let (f1, f2) = p;

Meta

I tried this on the latest nightly release of rustc using the rust playground and it still doesn't work. I'm still somewhat new with rust so let me know if this isn't a bug!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions