Skip to content

macro definitions escape from local scopes #4906

Description

@jbclements

I think (hope) this is an easy fix; I'm creating the issue so I can refer to it in code.

Currently, macros defined by macro_rules! escape from the contexts in which they're defined; I'm assuming that's an accident. So, for instance,

// regular definition of add1
macro_rules! add1 (
    ($x:expr) => ($x + 1)
)


fn boring () -> uint {
    // sneaky redefinition...
    macro_rules! add1 (
        ($x:expr) => ($x + 2)
    )
        3
}

fn scary () -> uint {
    // which definition is live?
    add1!(3)
}

#[test] fn t1 () {
    assert scary() == 4;
}

...fails the test, because the bogus definition from the boring() function is still in effect.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-syntaxextArea: Syntax extensions

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions