help for E0423 shows unhelpful expanded macro
Open
Nobody has claimed this yet.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
struct Foo{
attr: (),
}
fn main() {
Foo(vec![1]);
}
Current output
error[E0423]: expected function, tuple struct or tuple variant, found struct `Foo`
--> src/main.rs:6:5
|
1 | / struct Foo{
2 | | attr: (),
3 | | }
| |_- `Foo` defined here
...
6 | Foo(vec![1]);
| ^^^^^^^^^^^^
|
help: use struct literal syntax instead of calling
--> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/macros.rs:50:9
|
50 ~ {
51 ~ attr: <[_]>::into_vec(
52 | // Using the intrinsic produces a dramatic improvement in stack usage for
53 | // unoptimized programs using this code path to construct large Vecs.
54 | $crate::boxed::box_new([$($x),+])
55 ~ )}
|
Desired output
error[E0423]: expected function, tuple struct or tuple variant, found struct `Foo`
--> src/main.rs:6:5
|
1 | / struct Foo{
2 | | attr: (),
3 | | }
| |_- `Foo` defined here
...
6 | Foo(vec![1]);
| ^^^^^^^^^^^^
|
help: use struct literal syntax instead of calling
|
|
6 - Foo(vec![1]);
6 + Foo{attr: vec![1]};
|
|
Rationale and extra context
The expansion of vec! is irrelevant here. Also, the suggestion to change lines 50, 51 and 56 in alloc/src/macros.rs is wrong.
Other cases
The good output is shown when vec![1] is replaced with 1.
Rust Version
1.93.0-nightly 2025-11-25 80d8f292d82d735f8341
Stable: 1.91.1
Anything else?
No response
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 reproducing the E0423 example from the issue with the vec![1] argument and compare its diagnostic with the scalar-argument case. Trace the compiler's handling of the struct-literal suggestion and the expanded alloc/src/macros.rs span; done means the suggestion points to the source call and shows the desired Foo{attr: vec![1]} replacement without macro internals.
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
- Clearly specified
- Newbie friendliness
- 45/100