Open
Description
Consider this reduced test case:
macro_rules! match_ignore_ascii_case {
(@inner $value:expr) => { () };
( $($rest:tt)* ) => { match_ignore_ascii_case!(@inner $($rest)*) };
}
fn main() {
// This is fine
match_ignore_ascii_case!(1);
// This causes an error as it doesn’t match the expected syntax
// but the error message does not the location of the actual error.
match_ignore_ascii_case!(2 => 3);
}
The @inner
indirection exists because the non-reduced macro is recursive:
- https://play.rust-lang.org/?gist=f8b1652f43cc720f89a3&version=nightly
- https://users.rust-lang.org/t/writing-a-macro-rules-macro-used-like-a-match-expression/4328
This fails to compile (as it should) but the error message does not include the real location of the error, which is line 12. It can be hard to track down in a large crate with many users of the macro.
a.rs:3:52: 3:53 error: unexpected token: `@`
a.rs:3 ( $($rest:tt)* ) => { match_ignore_ascii_case!(@inner $($rest)*) };
The error message looks even worse when the macro is used (with incorrect syntax) from another crate
<cssparser macros>:12:1: 12:2 error: unexpected token: `@`
<cssparser macros>:12 @ inner $ value , ( $ ( $ rest ) * ) -> (
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Category: An issue proposing an enhancement or a PR with one.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.