Skip to content

Builtin indexing not used with non-trivial indices. #33903

Closed
@eddyb

Description

@eddyb

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

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions