Skip to content

self variable in macros is broken (regression) #15682

Closed
@netvl

Description

@netvl

This code does not compile (playpen), though it should:

#![feature(macro_rules)]

macro_rules! self_call(
    ($name:ident) => (self.$name())
)

struct X;

impl X {
    fn x(&self) {
        self_call!(y)
    }

    fn y(&self) {
        println!("Called y()");
    }
}

fn main() {
    X.x();
}

This is the error:

<anon>:4:23: 4:27 error: `self` is not available in a static method. Maybe a `self` argument is missing?
<anon>:4     ($name:ident) => (self.$name())
                               ^~~~
<anon>:3:1: 5:2 note: in expansion of self_call!
<anon>:11:9: 12:6 note: expansion site
error: aborting due to previous error

This worked previously (it certainly did on June, 8th - this is the last time I compiled my code which used such macro).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions