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

Confusing source location for "missing fragment specifier" #95463

Closed
mikebenfield opened this issue Mar 30, 2022 · 2 comments · Fixed by #129154
Closed

Confusing source location for "missing fragment specifier" #95463

mikebenfield opened this issue Mar 30, 2022 · 2 comments · Fixed by #129154
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-parser Area: The parsing of Rust source code to an AST. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mikebenfield
Copy link
Contributor

mikebenfield commented Mar 30, 2022

Here's some code incorrectly defining a macro, because it's missing a fragment specifier. Playground

macro_rules! m {
    ($x [$y: ident]) => {}
}

Here's the error message rustc gives me:

error: missing fragment specifier
 [--> src/lib.rs:2:9
](https://play.rust-lang.org/#)  |
2 |     ($x [$y: ident]) => {}
  |         ^^^^^^^^^^^
  |

It's potentially confusing that the error points to the source after the name with the missing fragment specifier. Especially in a complicated macro, it would be better if it pointed to the item which was actually missing the fragment specifier.

@mikebenfield mikebenfield added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 30, 2022
@estebank estebank added A-parser Area: The parsing of Rust source code to an AST. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Apr 23, 2022
@srleyva
Copy link

srleyva commented Apr 28, 2022

@rustbot claim

@tgross35
Copy link
Contributor

tgross35 commented Aug 14, 2024

Some more context at #129077

@bors bors closed this as completed in 5bceee4 Aug 16, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 16, 2024
Rollup merge of rust-lang#129154 - wafarm:fix-95463, r=estebank

Fix wrong source location for some incorrect macro definitions

Fixes rust-lang#95463

Currently the code will consume the next token tree after `var` when trying to parse `$var:some_type` even when it's not a `:` (e.g. a `$` when input is `($foo $bar:tt) => {}`). Additionally it will return the wrong span when it's not a `:`.

This PR fixes these problems.
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, ..) A-parser Area: The parsing of Rust source code to an AST. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants