Skip to content

Impossible to have a macro expand to pub method #17635

@mitsuhiko

Description

@mitsuhiko

Currently a macro cannot create a pub fn. It can however create a regular fn.

#![feature(macro_rules)]

macro_rules! foo (
    () => (
        pub fn foo() -> int {
            42
        }
    )
)

struct X;

impl X {
    foo!()
}

fn main() {
    println!("{}", X::foo());
}

Fails with:

$ rustc test.rs
test.rs:5:9: 5:12 error: unexpected token: `pub`
test.rs:5         pub fn foo() -> int {
                  ^~~

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