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

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

Merged
merged 1 commit into from
Apr 8, 2015
Merged

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

merged 1 commit into from
Apr 8, 2015

Conversation

whipsch
Copy link
Contributor

@whipsch whipsch commented Apr 4, 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.

@rust-highfive
Copy link
Collaborator

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
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
Copy link
Contributor Author

whipsch commented Apr 7, 2015

//~ NOTE was indeed correct.

@alexcrichton should be good to go

@alexcrichton
Copy link
Member

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

@rprichard
Copy link
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
Copy link
Member

huonw commented Apr 7, 2015

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
Copy link
Member

huonw commented Apr 7, 2015

@bors r+

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

@bors
Copy link
Contributor

bors commented Apr 7, 2015

📌 Commit ab32154 has been approved by huonw

@bors
Copy link
Contributor

bors commented Apr 7, 2015

⌛ 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
Copy link
Contributor

bors commented Apr 8, 2015

💔 Test failed - auto-mac-32-opt

@sfackler
Copy link
Member

sfackler commented Apr 8, 2015

@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
Copy link
Contributor

bors commented Apr 8, 2015

⌛ Testing commit ab32154 with merge ce97c19...

@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