Open
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.)
Metadata
Metadata
Assignees
Labels
Area: Lints (warnings about flaws in source code) such as unused_mut.Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Category: This is a bug.Diagnostics: A diagnostic that is giving misleading or incorrect information.Inline constants (aka: const blocks, const expressions, anonymous constants)Lint: unused_parensStatus: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.