Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eddyb opened this issue May 27, 2016 · 0 comments · Fixed by #47167
Closed

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

eddyb opened this issue May 27, 2016 · 0 comments · Fixed by #47167
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@eddyb
Copy link
Member

eddyb commented May 27, 2016

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];
  |>                  ^^^^^^^^^^^^^^^
@Mark-Simulacrum Mark-Simulacrum added the A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. label Jun 23, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 25, 2017
bors added a commit that referenced this issue Jan 10, 2018
Fix built-in indexing not being used where index type wasn't "obviously" usize

Fixes #33903
Fixes #46095

This PR was made possible thanks to the generous help of @eddyb

Following the example of binary operators, builtin checking for indexing has been moved from the typecheck stage to a writeback stage, after type constraints have been resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants