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

Badly placed 'Unexpected end of macro invocation' when calling a macro with no arguments #26615

Closed
thepowersgang opened this issue Jun 27, 2015 · 6 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@thepowersgang
Copy link
Contributor

When a macro that expects arguments is not passed any, the "unexpected end of macro invocation" message is placed at the start of the crate root file, instead of the invocation.

// Test case

macro_rules! mac {
    ($e:expr) => ("hello");
}

fn main() {
    println!("{}", mac!());
}
<anon>:1:1: 1:1 error: unexpected end of macro invocation
<anon>:1 // Test case
         ^
playpen: application terminated with error code 101
@steveklabnik steveklabnik added A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels Jun 29, 2015
@thepowersgang
Copy link
Contributor Author

Mostly fixed in #27584, above test case still produces a slightly unexpected result on playpen nightly, but points to the correct line (just to the println! invocation instead of mac!)

<anon>:8:5: 8:28 error: unexpected end of macro invocation
<anon>:8     println!("{}", mac!());
             ^~~~~~~~~~~~~~~~~~~~~~~

@elinorbgr
Copy link
Contributor

There are still some pathological cases, for example with this file:

fn main() {}

fn foo() {
    for _ in 0..3 {
        /*
            some
            code
            here
        */
        println!();
        /*
            some
            code
            here
        */
    }
}

The generated error (on nigthly playpen) is:

<anon>:4:5: 16:6 error: unexpected end of macro invocation
<anon>:4     for _ in 0..3 {
<anon>:5         /*
<anon>:6             some
<anon>:7             code
<anon>:8             here
<anon>:9         */
         ...

@TimNN
Copy link
Contributor

TimNN commented Sep 6, 2015

Both of theses examples probably have the same root cause: The "unexpected end of macro invocation" error apparently always reports the span of the outermost ast node which requires expansion. See this gist (playground) for some examples of which span is reported in different contexts.

@TimNN
Copy link
Contributor

TimNN commented Oct 30, 2015

The situation seems to have improved in the latest nightly: now only nested macro invocations have an incorrect spam and not macro invocations inside of other expanded things. Updated gist (playground).

@TimNN
Copy link
Contributor

TimNN commented Oct 30, 2015

Looking over some pr's since my last comment, the improvement probably happened as part of #28857.

@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum
Copy link
Member

As noted above, non-nested macro invocations are now fixed, and those are tracked separately (#33871). Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
Projects
None yet
Development

No branches or pull requests

5 participants