"convert path expression -> struct expression" points at the path, instead of the path expression
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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.
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 Rust macro reproducer in the issue and compare the current and desired diagnostics. Trace compiler diagnostic handling for the $p:path fragment when it is interpreted as an expression; done means the error points to ($p) at the macro definition and gives the valid braced suggestion described in the issue.
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
- 42/100