Closed
Description
Move semantics with declarative macros 2.0 are broken. Can copy non-copy types.
Playground
#![feature(decl_macro)]
#![allow(unused_macros)]
#[derive(Debug)]
struct NonCopy(String);
struct Foo {
x: NonCopy,
}
macro copy($foo:ident) {
$foo.x
}
macro_rules! copy2 {
($foo:ident) => {
$foo.x
}
}
fn main() {
let foo = Foo { x: NonCopy("foo".into()) };
assert_two_copies(copy!(foo), foo.x);
// A similar old-style macro will not work:
//assert_two_copies(copy2!(foo), foo.x);
}
fn assert_two_copies(a: NonCopy, b: NonCopy) {
println!("Got two copies: {:?}, {:?}", a, b);
}
rustc --version --verbose:
rustc 1.23.0-nightly (63739ab7b 2017-11-21)
binary: rustc
commit-hash: 63739ab7b210c1a8c890c2ea5238a3284877daa3
commit-date: 2017-11-21
host: x86_64-unknown-linux-gnu
release: 1.23.0-nightly
LLVM version: 4.0