Misleading error messages when using the wrong macro fragment specifiers
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Issue:
#[rustfmt::skip]
mod issue {
struct SomeType<T>(std::marker::PhantomData<T>);
macro_rules! test {
($ty:ty) => {
impl<$ty,> SomeType<$ty> {}
};
}
// Works fine
impl<T,> SomeType<T> {}
// error: expected one of `>` or `as`, found `,`
// --> src\lib.rs:7:21
// |
// 7 | impl<$ty,> SomeType<$ty> {}
// | ^ expected one of `>` or `as`
// ...
// 12 | test!(T);
// | -------- in this macro invocation
test!(T);
macro_rules! test2 {
($ty:ty) => {
impl<$ty> SomeType<$ty> {}
};
}
// Works fine
impl<T> SomeType<T> {}
// error: expected `::`, found `SomeType`
// --> src\lib.rs:17:23
// |
// 17 | impl<$ty> SomeType<$ty> {}
// | ^^^^^^^^ expected `::`
// ...
// 22 | test2!(T);
// | --------- in this macro invocation
test2!(T);
}
The macro should behave exactly like its manual expansion would; I've inlined the reported problems into the code.
Meta
The error happens in both stable and nightly toolchains, on linux and windows
rustc --version --verbose:
rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-pc-windows-msvc
release: 1.82.0
LLVM version: 19.1.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the inline macro reproducer with the affected rustc toolchain and compare its diagnostics with the manual expansions shown in the issue. The issue names no source files or tests, so locate the compiler handling for macro fragment expansion and diagnostics. Done means the macro errors communicate the corresponding manual-expansion problem rather than pointing to misleading tokens.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100