-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Description
It appears that when it's not obvious the index type is usize
, we fall back to overloaded indexing:
const FOO: i32 = [12, 34][0 + 1];
Fails in constant checking, on stable:
<anon>:1:18: 1:33 error: user-defined operators are not allowed in constants [E0011]
<anon>:1 const FOO: i32 = [12, 34][0 + 1];
^~~~~~~~~~~~~~~
And also with the new MIR-based constant checker, on nightly:
error: calls in constants are limited to constant functions, struct and enum constructors [E0015]
--> <anon>:1:18
1 |> const FOO: i32 = [12, 34][0 + 1];
|> ^^^^^^^^^^^^^^^
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.