Rust: ์ค‘๊ฐ„ let ๋ฐ”์ธ๋”ฉ ์—†์ด๋Š” boxed struct๋ฅผ ๋ถ„ํ•ด ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์— ๋งŒ๋“  2018๋…„ 01์›” 12์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: rust-lang/rust

์ด ์ฝ”๋“œ๋Š” ์ปดํŒŒ์ผ์— ์‹คํŒจํ•ฉ๋‹ˆ๋‹ค.

struct Foo;

struct Bar {
    a: Foo,
    b: Foo,
}

fn main() {
    let bar = Box::new(Bar { a: Foo, b: Foo });

    let Bar { a, b } = *bar;
}
error[E0382]: use of moved value: `bar`
  --> x.rs:11:18
   |
11 |     let Bar { a, b } = *bar;
   |               -  ^ value used here after move
   |               |
   |               value moved here
   |
   = note: move occurs because `bar.a` has type `Foo`, which does not implement the `Copy` trait

๊ทธ๋Ÿฌ๋‚˜ ์ƒ์ž deref์™€ destructure ์‚ฌ์ด์— ์ค‘๊ฐ„ let ๋ฐ”์ธ๋”ฉ์„ ์‚ฝ์ž…ํ•˜๋ฉด ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋ฉ๋‹ˆ๋‹ค.

fn main() {
    let bar = Box::new(Bar { a: Foo, b: Foo });

    let Bar { a, b } = { let intermediate = *bar; intermediate };
}

์ด๊ฒƒ์€ ๋ฒ„๊ทธ์ฒ˜๋Ÿผ ๋Š๊ปด์ง‘๋‹ˆ๋‹ค.

์˜ํ–ฅ์„๋ฐ›๋Š” ๋ฒ„์ „ :

  • rustc 1.23.0 (766bd11c8 2018-01-01)

  • rustc 1.25.0-nightly (73ac5d6a8 2018-01-11)

C-bug T-compiler

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

์ƒ์ž ํŒจํ„ด์—์„œ๋„ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

#![feature(box_patterns)]

struct Foo;

struct Bar {
    a: Foo,
    b: Foo,
}

fn main() {
    let bar = Box::new(Bar { a: Foo, b: Foo });

    let box Bar { a, b } = bar;
}

๋ชจ๋“  3 ๋Œ“๊ธ€

์ƒ์ž ํŒจํ„ด์—์„œ๋„ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

#![feature(box_patterns)]

struct Foo;

struct Bar {
    a: Foo,
    b: Foo,
}

fn main() {
    let bar = Box::new(Bar { a: Foo, b: Foo });

    let box Bar { a, b } = bar;
}

์ด๊ฒƒ์€ https://github.com/rust-lang/rust/issues/16223 ์˜ ์†์ž„์ˆ˜์ž…๋‹ˆ๋‹ค

๋ถ„๋ฅ˜ :์ด ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰