Skip to content

Macro declarations do not work in impl blocks #37205

@KiChjang

Description

@KiChjang

Minimal test case:

struct Foo; impl Foo { macro_rules! bar { () => ( println!("Hi"); ); } pub fn say() { bar!(); } } fn main() { Foo::say(); }

On stable it emits the following error:

rustc 1.12.0 (3191fbae9 2016-09-23) error: expected one of `const`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `macro_rules` --> <anon>:4:5 | 4 | macro_rules! bar { | ^^^^^^^^^^^ error: aborting due to previous error 

And on beta or nightly, it emits the following instead:

rustc 1.14.0-nightly (6e8f92f11 2016-10-07) error: expected open delimiter --> <anon>:4:18 | 4 | macro_rules! bar { | ^^^ error: aborting due to previous error 

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-parserArea: The lexing & parsing of Rust source code to an ASTC-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions