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

Comments

@eddyb
Copy link
Member

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];
  |>                  ^^^^^^^^^^^^^^^
bors added a commit that referenced this issue Jan 9, 2018
Auto merge of #47167 - ivanbakel:builtin_indexing, r=nikomatsakis
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.
bors added a commit that referenced this issue Jan 9, 2018
Auto merge of #47167 - ivanbakel:builtin_indexing, r=nikomatsakis
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.
bors added a commit that referenced this issue Jan 10, 2018
Auto merge of #47167 - ivanbakel:builtin_indexing, r=nikomatsakis
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.

@bors bors closed this in #47167 Jan 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.