Skip to content

Impls inside of macros doesn't work #4651

Closed
@auroranockert

Description

@auroranockert

For example, this doesn't work.

macro_rules! Q(($T:ty, $f:expr, $name:ident) => {
  struct $name {
    value: $T
  }

  impl $name {
    pure fn add(&self, other: &$name) -> $name {
      $name { value: self.value + other.value }
    }
  }
})

Q!(i8, 8, Q8)

fn main() {
  let a = Q8 { value: 4 };
  let b = Q8 { value: 8 };

  io::println(fmt!("Q8: %?", &a.add(&b)))
}

and gives the error,

error: type `Q8` does not implement any method in scope named `add`
io::println(fmt!("Q8: %?", &a.add(&b)))

the intended effect is something like,

Q8: {value: 12}

should be printed to stdout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-syntaxextArea: Syntax extensions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions