Skip to content

Provide context for macro expansions which result in unparsed tokens.#24078

Merged
bors merged 1 commit into
rust-lang:masterfrom
whipsch:extra-token-msg
Apr 8, 2015
Merged

Provide context for macro expansions which result in unparsed tokens.#24078
bors merged 1 commit into
rust-lang:masterfrom
whipsch:extra-token-msg

Conversation

@whipsch

@whipsch whipsch commented Apr 4, 2015

Copy link
Copy Markdown
Contributor

Addresses issue #22425. See src/test/compile-fail/macro-incomplete-parse.rs for a relevant test:

macro-incomplete-parse.rs:15:9: 15:10 error: macro expansion ignores token `,` and any following
macro-incomplete-parse.rs:15         , //~ ERROR macro expansion ignores token `,`
                                     ^
macro-incomplete-parse.rs:27:1: 27:17 note: caused by the macro expansion here; the usage of `ignored_item` is likely invalid in this context
macro-incomplete-parse.rs:27 ignored_item!();
                             ^~~~~~~~~~~~~~~~
macro-incomplete-parse.rs:20:14: 20:15 error: macro expansion ignores token `,` and any following
macro-incomplete-parse.rs:20     () => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
                                          ^
macro-incomplete-parse.rs:30:5: 30:21 note: caused by the macro expansion here; the usage of `ignored_expr` is likely invalid in this context
macro-incomplete-parse.rs:30     ignored_expr!();
                                 ^~~~~~~~~~~~~~~~
macro-incomplete-parse.rs:24:14: 24:15 error: macro expansion ignores token `,` and any following
macro-incomplete-parse.rs:24     () => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
                                          ^
macro-incomplete-parse.rs:32:9: 32:23 note: caused by the macro expansion here; the usage of `ignored_pat` is likely invalid in this context
macro-incomplete-parse.rs:32         ignored_pat!() => (),
                                     ^~~~~~~~~~~~~~

This does not address the case of improper expansion inside of an impl { } as seen in issue #21607.

I'm not sure if the note text is ideal, but it can be refined if needed.

@rust-highfive

Copy link
Copy Markdown
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pcwalton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see CONTRIBUTING.md for more information.

@alexcrichton

Copy link
Copy Markdown
Member

Thanks! Could you update the test case as well with this error message? I believe //~ NOTE or something similar should provide a good assertion that it's being emitted.

Also, could you rebase out the merge commit in the middle?

@alexcrichton alexcrichton assigned alexcrichton and unassigned pcwalton Apr 6, 2015
@whipsch

whipsch commented Apr 7, 2015

Copy link
Copy Markdown
Contributor Author

//~ NOTE was indeed correct.

@alexcrichton should be good to go

@alexcrichton

Copy link
Copy Markdown
Member

Thanks! r? @kmcallister or @huonw or @sfackler (probably shoulda done that earlier as well..)

@rprichard

Copy link
Copy Markdown
Contributor

When macro invocations expand to other macro invocations, I believe this fix only prints one of the call sites (either the immediate site or the earliest site, probably). Is that right? There will be a complete backtrace in the ExtCtxt::backtrace() value -- maybe we ought to print it?

It seems there's a family of issues whose root cause is that we don't print a macro backtrace while we're parsing -- only after parsing/expansion has attached backtraces to spans. I'm wondering if they all have a single fix -- when we print a parsing error, also print the current ExtCtxt::backtrace().

Other issues include:

@huonw

huonw commented Apr 7, 2015

Copy link
Copy Markdown
Contributor

I'm wondering if they all have a single fix -- when we print a parsing error, also print the current ExtCtxt::backtrace().

That sounds like a good idea to me, although the specific information offered by this patch is good too.

@huonw

huonw commented Apr 7, 2015

Copy link
Copy Markdown
Contributor

@bors r+

(We can add/swap in a more general approach in future.)

@bors

bors commented Apr 7, 2015

Copy link
Copy Markdown
Collaborator

📌 Commit ab32154 has been approved by huonw

@bors

bors commented Apr 7, 2015

Copy link
Copy Markdown
Collaborator

⌛ Testing commit ab32154 with merge aecd165...

bors added a commit that referenced this pull request Apr 7, 2015
Addresses issue #22425.  See `src/test/compile-fail/macro-incomplete-parse.rs` for a relevant test:

    macro-incomplete-parse.rs:15:9: 15:10 error: macro expansion ignores token `,` and any following
    macro-incomplete-parse.rs:15         , //~ ERROR macro expansion ignores token `,`
                                         ^
    macro-incomplete-parse.rs:27:1: 27:17 note: caused by the macro expansion here; the usage of `ignored_item` is likely invalid in this context
    macro-incomplete-parse.rs:27 ignored_item!();
                                 ^~~~~~~~~~~~~~~~
    macro-incomplete-parse.rs:20:14: 20:15 error: macro expansion ignores token `,` and any following
    macro-incomplete-parse.rs:20     () => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
                                              ^
    macro-incomplete-parse.rs:30:5: 30:21 note: caused by the macro expansion here; the usage of `ignored_expr` is likely invalid in this context
    macro-incomplete-parse.rs:30     ignored_expr!();
                                     ^~~~~~~~~~~~~~~~
    macro-incomplete-parse.rs:24:14: 24:15 error: macro expansion ignores token `,` and any following
    macro-incomplete-parse.rs:24     () => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
                                              ^
    macro-incomplete-parse.rs:32:9: 32:23 note: caused by the macro expansion here; the usage of `ignored_pat` is likely invalid in this context
    macro-incomplete-parse.rs:32         ignored_pat!() => (),
                                         ^~~~~~~~~~~~~~

This does not address the case of improper expansion inside of an impl { } as seen in issue #21607.


I'm not sure if the note text is ideal, but it can be refined if needed.
@bors

bors commented Apr 8, 2015

Copy link
Copy Markdown
Collaborator

💔 Test failed - auto-mac-32-opt

@sfackler

sfackler commented Apr 8, 2015

Copy link
Copy Markdown
Member

@bors: retry

bors added a commit that referenced this pull request Apr 8, 2015
Addresses issue #22425.  See `src/test/compile-fail/macro-incomplete-parse.rs` for a relevant test:

    macro-incomplete-parse.rs:15:9: 15:10 error: macro expansion ignores token `,` and any following
    macro-incomplete-parse.rs:15         , //~ ERROR macro expansion ignores token `,`
                                         ^
    macro-incomplete-parse.rs:27:1: 27:17 note: caused by the macro expansion here; the usage of `ignored_item` is likely invalid in this context
    macro-incomplete-parse.rs:27 ignored_item!();
                                 ^~~~~~~~~~~~~~~~
    macro-incomplete-parse.rs:20:14: 20:15 error: macro expansion ignores token `,` and any following
    macro-incomplete-parse.rs:20     () => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
                                              ^
    macro-incomplete-parse.rs:30:5: 30:21 note: caused by the macro expansion here; the usage of `ignored_expr` is likely invalid in this context
    macro-incomplete-parse.rs:30     ignored_expr!();
                                     ^~~~~~~~~~~~~~~~
    macro-incomplete-parse.rs:24:14: 24:15 error: macro expansion ignores token `,` and any following
    macro-incomplete-parse.rs:24     () => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
                                              ^
    macro-incomplete-parse.rs:32:9: 32:23 note: caused by the macro expansion here; the usage of `ignored_pat` is likely invalid in this context
    macro-incomplete-parse.rs:32         ignored_pat!() => (),
                                         ^~~~~~~~~~~~~~

This does not address the case of improper expansion inside of an impl { } as seen in issue #21607.


I'm not sure if the note text is ideal, but it can be refined if needed.
@bors

bors commented Apr 8, 2015

Copy link
Copy Markdown
Collaborator

⌛ Testing commit ab32154 with merge ce97c19...

@bors

bors commented Apr 8, 2015

Copy link
Copy Markdown
Collaborator

@bors bors merged commit ab32154 into rust-lang:master Apr 8, 2015
@whipsch whipsch deleted the extra-token-msg branch April 9, 2015 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants