Inappropriate `unused_parens` for inline `const` inside `vec!`/macros
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
In this example, the inline const must be wrapped in parentheses, in order to work inside vec! under editions <2024:
fn main() {
// Works fine, no warning.
let _: [Vec<String>; 10] = [const { vec![] }; 10];
// Works fine, no warning.
let _: Vec<Vec<String>> = vec![(const { vec![] })];
// Works, but warns about unnecessary parentheses.
let _: Vec<Vec<String>> = vec![(const { vec![] }); 10]; // <=== THIS
// These fail on stable79/beta80/nightly81 with edition 2021.
// They work on nightly81 with edition 2024.
let _: Vec<Vec<String>> = vec![const { vec![] }];
let _: Vec<Vec<String>> = vec![const { vec![] }; 10];
}
However, notice that in the case of vec![(const { vec![] }); 10], the compiler accepts the code but warns that the parentheses are unnecessary:
warning: unnecessary parentheses around function argument
--> src/main.rs:8:36
|
8 | let _: Vec<Vec<String>> = vec![(const { vec![] }); 10];
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
8 - let _: Vec<Vec<String>> = vec![(const { vec![] }); 10];
8 + let _: Vec<Vec<String>> = vec![const { vec![] }; 10];
|
The warning is incorrect, because removing the parentheses would result in an error under edition <2024.
(The vec![(const { vec![] })] case correctly reports no warning.)
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 provided playground reproducer for editions 2021 and 2024, comparing the inline const cases inside vec!. Trace how the unused_parens lint interacts with vec! macro expansion and inline const parsing. Done means the required parentheses are not reported as unnecessary while genuinely unnecessary parentheses still receive the lint.
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