- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-decl-macros-2-0Area: Declarative macros 2.0 (#39412)Area: Declarative macros 2.0 (#39412)C-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priority
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
durka
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-decl-macros-2-0Area: Declarative macros 2.0 (#39412)Area: Declarative macros 2.0 (#39412)C-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priority