Skip to content

Can't implement traits in declarative macros. #44128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Lymia opened this issue Aug 28, 2017 · 1 comment
Closed

Can't implement traits in declarative macros. #44128

Lymia opened this issue Aug 28, 2017 · 1 comment
Assignees
Labels
A-decl-macros-2-0 Area: Declarative macros 2.0 (#39412) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Lymia
Copy link
Contributor

Lymia commented Aug 28, 2017

Implementing traits doesn't seem to work either in declarative macros. This code looks like it should compile:

#![feature(decl_macro)]

pub macro create_struct($a:ident) {
    struct $a;
    impl Clone for $a {
        fn clone(&self) -> Self {
            $a
        }
    }
}

fn main() {
    create_struct!(Test);
    Test.clone();
}

But it does this instead:

   Compiling playground v0.0.1 (file:///playground)
error[E0046]: not all trait items implemented, missing: `clone`
  --> src/main.rs:5:5
   |
5  | /     impl Clone for $a {
6  | |         fn clone(&self) -> Self {
7  | |             $a
8  | |         }
9  | |     }
   | |_____^ missing `clone` in implementation
...
13 |       create_struct!(Test);
   |       --------------------- in this macro invocation
   |
   = note: `clone` from trait: `fn(&Self) -> Self`

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.
@carols10cents carols10cents added A-decl-macros-2-0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 28, 2017
@jseyfried
Copy link
Contributor

Looks like this has been fixed.

@jseyfried jseyfried added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed C-bug Category: This is a bug. labels Dec 1, 2017
@jseyfried jseyfried self-assigned this Dec 1, 2017
jseyfried added a commit to jseyfried/rust that referenced this issue Dec 7, 2017
bors added a commit that referenced this issue Dec 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-decl-macros-2-0 Area: Declarative macros 2.0 (#39412) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants