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

error w/ macros that expand into macro definitions #6795

Closed
jbclements opened this issue May 28, 2013 · 7 comments
Closed

error w/ macros that expand into macro definitions #6795

jbclements opened this issue May 28, 2013 · 7 comments
Labels
A-syntaxext Area: Syntax extensions E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.

Comments

@jbclements
Copy link
Contributor

One of my expansion test cases causes an ICE:

macro_rules! g (
    ($x:ident) =>
    ({
        macro_rules! f(($y:ident)=>
                       ({
                           let $y=3;
                           $x
                       }));
        f!($x)
    }))

fn a() {
    g!(z);
}

=>

Running /usr/local/bin/rustc:
rust: task failed at 'No entry found for key: &{name: 39, ctxt: 0}', /Users/clements/rust/src/libcore/hashmap.rs:490
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /Users/clements/rust/src/librustc/rustc.rc:351
rust: domain main @0x7fabf9819210 root task failed

before going further, I must check that this happens on incoming as well as my branch....

@ghost ghost assigned jbclements May 28, 2013
@jbclements
Copy link
Contributor Author

Good news... after an update, it now provides a nice error message rather than an ICE. It appears that rust does not currently support macros that expand into macro definitions.

Specifically:

Running /Users/clements/rust/build/x86_64-apple-darwin/stage2/bin/rustc:
/tmp/foo.rs:4:23: 4:24 error: unknown macro variable `y`
/tmp/foo.rs:4         macro_rules! f(($y:ident)=>
                                     ^

It appears that macro expansion insists that all identifiers preceded by a $ must be already bound to syntax terms. Fixing this will probably require a bunch of steps.

@jbclements
Copy link
Contributor Author

update and more detail on this: the central issue here appears to be that macro invocation bodies are "too parsed, too soon." More specifically: macro invocation bodies are not parsed into ASTs, they're kept as token trees. That's good. However, the token tree language is designed to allow these token trees to contain pattern variable references. That is, pattern variables are identified when the macro is parsed into a token tree. This is bad, because you don't yet know whether a given pattern variable is a pattern variable binding or a pattern variable use. I believe the solution is to delay this decision until macro expansion time.

@emberian
Copy link
Member

Visiting for triage; still reproduces.

@huonw
Copy link
Member

huonw commented Jan 19, 2014

Still an issue.

@klutzy
Copy link
Contributor

klutzy commented Feb 25, 2014

Still an issue. (revision 6720977)
If $y is removed (macro_rules! f(() => ...)), rustc produces ICE: #10536

@jbclements jbclements removed their assignment Jun 16, 2014
@huonw
Copy link
Member

huonw commented Jul 13, 2014

Now that the ICE has been fixed, is this a dupe of #6994?

@jbclements
Copy link
Contributor Author

yes, looks that way to me.

@huonw huonw closed this as completed Jul 13, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 11, 2021
Downgrade manual_map to nursery

I believe rust-lang#6795 should be considered a blocker for this lint to be considered for enabling by default.

---

changelog: remove manual_map from default list of enabled lints
flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 11, 2021
Fix `manual_map` false positives

fixes: rust-lang#6795
fixes: rust-lang#6797
fixes: rust-lang#6811
fixes: rust-lang#6819

changelog: Fix false positives for `manual_map` when `return`, `break`, `continue`, `yield`, `await`, and partially moved values are used.
changelog: Don't expand macros in suggestions  for `manual_map`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.
Projects
None yet
Development

No branches or pull requests

4 participants