Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macro definitions escape from local scopes #4906

Closed
jbclements opened this issue Feb 12, 2013 · 2 comments
Closed

macro definitions escape from local scopes #4906

jbclements opened this issue Feb 12, 2013 · 2 comments
Labels
A-syntaxext Area: Syntax extensions
Milestone

Comments

@jbclements
Copy link
Contributor

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.

@graydon
Copy link
Contributor

graydon commented Feb 13, 2013

There is no scoping mechanism for syntax expander names at all (thus macro names). There should be. There always should have been, and we punted on it over and over while working on other "more important" issues.

See also #3114 and #2247. This is work that remains to be done. It would be fantastic if you were to, say, propose and implement something here. Almost anything would be better than the current situation.

@jbclements
Copy link
Contributor Author

I'm closing this now. Macros now escape only from modules that use the #[macro_escape] attribute.

flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 28, 2020
…nts, r=Manishearth,flip1995

Parse doctests in needless_doctest_main

This switches from text-based search to running the parser to avoid false positives. Inspired by how [rustdoc](https://github.com/rust-lang/rust/blob/3f3250500fe152b5759c21453ba9a9129808d0d8/src/librustdoc/test.rs#L366) handles this and by rust-lang#4729.

cc @llogiq

changelog: Fix multiple false positives in [`needless_doctest_main`].

Fixes rust-lang#5879
Fixes rust-lang#4906
Fixes rust-lang#5103
Fixes rust-lang#4698
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions
Projects
None yet
Development

No branches or pull requests

2 participants