Suggest creating a const
when calling a const
function in an array initializer
#73734
Labels
A-const-eval
Area: Constant evaluation, covers all const contexts (static, const fn, ...)
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
E-easy
Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
E-mentor
Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
The following code:
gives the following error:
However,
String::new()
is aconst fn
, so this code can be made to compile by creating a newconst
item:We should suggest this to user when a
const
function is being called in the array initializer.Assuming that rust-lang/rfcs#2920 is accepted, we could eventually suggest an inlineconst
block.On Nightly, we could suggest an inline
const
block.The text was updated successfully, but these errors were encountered: