Open
Description
Code
macro_rules! m {
($p:path) => {
($p)
}
}
struct T {}
fn main() {
m!(T);
}
Current output
error[E0423]: expected value, found struct `T`
--> src/main.rs:10:8
|
7 | struct T {}
| ----------- `T` defined here
...
10 | m!(T);
| ^ help: use struct literal syntax instead: `T {}`
Desired output
error[E0423]: expected value, found struct `T`
--> src/main.rs:3:10
|
3 | ($p)
| ^^ help: use struct literal syntax instead: `$p {}`
...
7 | struct T {}
| ----------- `T` defined here
Rationale and extra context
This diagnostic points at the span of the path that resolved to a struct.
But that path is being parsed as a $:path
fragment, so there cannot be a struct expression in this location.
The diagnostic should point at the span of where the path was first interpreted as an expression, not at the span of the path itself.
Rust Version
rustc 1.90.0-nightly (11ad40bb8 2025-06-28)
binary: rustc
commit-hash: 11ad40bb839ca16f74784b4ab72596ad85587298
commit-date: 2025-06-28
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7
Anything else?
It's also worth noting that the $p {}
suggestion i included would also not be valid, because of a parsing bug in the compiler. That bug is tracked in #143221
While that parser bug persists, a valid suggestion would instead be like so:
error: expected value, found struct `T`
--> src/main.rs:3:10
|
3 | ($p)
| ^^ help: use struct literal syntax instead: `{ $p {} }`
...
7 | struct T {}
| ----------- `T` defined here
The details of why those braces are necessary are explained in the issue for the parser bug.