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

No expansion backtrace for macro where contents does not parse #23243

Closed
huonw opened this issue Mar 10, 2015 · 2 comments
Closed

No expansion backtrace for macro where contents does not parse #23243

huonw opened this issue Mar 10, 2015 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug.

Comments

@huonw
Copy link
Member

huonw commented Mar 10, 2015

macro_rules! foo {
    (item) => { fn not_a_pattern() {} };
    (pattern) => { ref _x }
}
fn main() {
    foo!(pattern);
    let foo!(item) = ();
}
<anon>:3:20: 3:23 error: expected identifier, found keyword `ref`
<anon>:3     (pattern) => { ref _x }
                            ^~~
<anon>:3:24: 3:26 error: macro expansion ignores token `_x` and any following
<anon>:3     (pattern) => { ref _x }
                                ^~
<anon>:2:17: 2:19 error: expected identifier, found keyword `fn`
<anon>:2     (item) => { fn not_a_pattern() {} };
                         ^~
<anon>:2:20: 2:33 error: macro expansion ignores token `not_a_pattern` and any following
<anon>:2     (item) => { fn not_a_pattern() {} };
                            ^~~~~~~~~~~~~
error: aborting due to 4 previous errors

The error messages should point to the respective foo! invocations, not just the contents of the macro, like

<anon>:3:20: 3:23 error: expected identifier, found keyword `ref`
<anon>:3     (pattern) => { ref _x }
                            ^~~
<anon>:1:1: 4:2 note: in expansion of foo!
<anon>:6:5: 6:19 note: expansion site
@huonw huonw added A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels Mar 10, 2015
@steveklabnik
Copy link
Member

Triage: only the first and third errors show now, but don't mention foo! at all.

@Mark-Simulacrum Mark-Simulacrum added C-enhancement Category: An issue proposing an enhancement or a PR with one. C-bug Category: This is a bug. and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jul 22, 2017
@estebank
Copy link
Contributor

Current output points at macro invocation of every syntax error inside of a macro definition:

error: expected expression, found keyword `ref`
 --> src/main.rs:3:20
  |
3 |     (pattern) => { ref _x }
  |                    ^^^
...
6 |     foo!(pattern);
  |     -------------- in this macro invocation

error: expected pattern, found keyword `fn`
 --> src/main.rs:2:17
  |
2 |     (item) => { fn not_a_pattern() {} };
  |                 ^^
...
7 |     let foo!(item) = ();
  |         ---------- in this macro invocation

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, ..) C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants