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

typeck: Fix const generic in repeat param ICE. #61698

Merged
merged 1 commit into from Jun 12, 2019

Conversation

Projects
None yet
6 participants
@davidtwco
Copy link
Member

commented Jun 9, 2019

Fixes #61336. Turns out this wasn't related to #49147 after all.

r? @varkor

@davidtwco davidtwco force-pushed the davidtwco:ice-const-generic-length branch from 0efc78c to cdcb7e6 Jun 9, 2019

@davidtwco davidtwco force-pushed the davidtwco:ice-const-generic-length branch from cdcb7e6 to 2a3e004 Jun 10, 2019

Show resolved Hide resolved src/librustc_typeck/check/mod.rs Outdated
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash

fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
[x; N]

This comment has been minimized.

Copy link
@varkor

varkor Jun 10, 2019

Member

Could we also have a test where we make sure that this does the right thing? E.g. pass in N explicitly and check the return value.

This comment has been minimized.

Copy link
@davidtwco

davidtwco Jun 10, 2019

Author Member

I've added another test. It will error later in the compiler with a "array lengths can't depend on generic parameters" error, emitted when creating the HAIR. From a quick look, it appears that the MIR/HAIR data structures all contain a u64 for the count, so it isn't trivial to change one or two lines and make this work, probably best left for a follow-up (which I'd be interested in trying to tackle). It's an improvement over an ICE in any case.

This comment has been minimized.

Copy link
@varkor

varkor Jun 10, 2019

Member

Ah, okay. Yes, this is certainly better than an ICE, and this gives us a good minimal example to fix. Let's open an issue for it after this is merged.

Show resolved Hide resolved src/librustc_typeck/check/mod.rs
typeck: Fix const generic in repeat param ICE.
This commit fixes an ICE that occured when a const generic was used in
a repeat expression. This was due to the code expecting the length of
the repeat expression to be const evaluatable to a constant, but a const
generic parameter is not (however, it can be made into a constant).

@davidtwco davidtwco force-pushed the davidtwco:ice-const-generic-length branch from 2a3e004 to 9ed4674 Jun 10, 2019

@varkor

This comment has been minimized.

Copy link
Member

commented Jun 10, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2019

📌 Commit 9ed4674 has been approved by varkor

Centril added a commit to Centril/rust that referenced this pull request Jun 11, 2019

Rollup merge of rust-lang#61698 - davidtwco:ice-const-generic-length,…
… r=varkor

typeck: Fix const generic in repeat param ICE.

Fixes rust-lang#61336. Turns out this wasn't related to rust-lang#49147 after all.

r? @varkor

Centril added a commit to Centril/rust that referenced this pull request Jun 11, 2019

Rollup merge of rust-lang#61698 - davidtwco:ice-const-generic-length,…
… r=varkor

typeck: Fix const generic in repeat param ICE.

Fixes rust-lang#61336. Turns out this wasn't related to rust-lang#49147 after all.

r? @varkor

bors added a commit that referenced this pull request Jun 11, 2019

Auto merge of #61737 - Centril:rollup-wsgxnyq, r=Centril
Rollup of 11 pull requests

Successful merges:

 - #61526 (move some tests into subfolders)
 - #61550 (Windows 10 SDK is also required now.)
 - #61606 (Remove some legacy proc macro flavors)
 - #61639 (Bootstrap cleanup)
 - #61686 (librustc_errors: Add some more documentation)
 - #61698 (typeck: Fix const generic in repeat param ICE.)
 - #61707 (Azure: retry failed awscli installs)
 - #61715 (make sure make_ascii_lowercase actually leaves upper-case non-ASCII characters alone)
 - #61720 (std: Remove internal definitions of `cfg_if!` macro)
 - #61724 (core: use memcmp optimization for 128 bit integer slices)
 - #61726 (Use `for_each` in `Iterator::partition`)

Failed merges:

r? @ghost

Centril added a commit to Centril/rust that referenced this pull request Jun 11, 2019

Rollup merge of rust-lang#61698 - davidtwco:ice-const-generic-length,…
… r=varkor

typeck: Fix const generic in repeat param ICE.

Fixes rust-lang#61336. Turns out this wasn't related to rust-lang#49147 after all.

r? @varkor

bors added a commit that referenced this pull request Jun 11, 2019

Auto merge of #61741 - Centril:rollup-fgro5kz, r=Centril
Rollup of 11 pull requests

Successful merges:

 - #61518 (Add loops to doc list of things not stable in const fn)
 - #61526 (move some tests into subfolders)
 - #61550 (Windows 10 SDK is also required now.)
 - #61606 (Remove some legacy proc macro flavors)
 - #61652 (Mention slice patterns in array)
 - #61686 (librustc_errors: Add some more documentation)
 - #61698 (typeck: Fix const generic in repeat param ICE.)
 - #61707 (Azure: retry failed awscli installs)
 - #61715 (make sure make_ascii_lowercase actually leaves upper-case non-ASCII characters alone)
 - #61724 (core: use memcmp optimization for 128 bit integer slices)
 - #61726 (Use `for_each` in `Iterator::partition`)

Failed merges:

r? @ghost

bors added a commit that referenced this pull request Jun 11, 2019

Auto merge of #61741 - Centril:rollup-fgro5kz, r=Centril
Rollup of 11 pull requests

Successful merges:

 - #61518 (Add loops to doc list of things not stable in const fn)
 - #61526 (move some tests into subfolders)
 - #61550 (Windows 10 SDK is also required now.)
 - #61606 (Remove some legacy proc macro flavors)
 - #61652 (Mention slice patterns in array)
 - #61686 (librustc_errors: Add some more documentation)
 - #61698 (typeck: Fix const generic in repeat param ICE.)
 - #61707 (Azure: retry failed awscli installs)
 - #61715 (make sure make_ascii_lowercase actually leaves upper-case non-ASCII characters alone)
 - #61724 (core: use memcmp optimization for 128 bit integer slices)
 - #61726 (Use `for_each` in `Iterator::partition`)

Failed merges:

r? @ghost

@bors bors merged commit 9ed4674 into rust-lang:master Jun 12, 2019

1 check passed

Travis CI - Pull Request Build Passed
Details

@davidtwco davidtwco deleted the davidtwco:ice-const-generic-length branch Jun 12, 2019

davidtwco added a commit to davidtwco/rust that referenced this pull request Jun 13, 2019

typeck: Fix ICE for blocks in repeat expr count.
This commit extends the work in rust-lang#61698 to get the `DefId` of const
parameters from block that resolve to a const parameter (as well as
const parameters directly, as it was previously).

davidtwco added a commit to davidtwco/rust that referenced this pull request Jun 13, 2019

typeck: Fix ICE for blocks in repeat expr count.
This commit extends the work in rust-lang#61698 to get the `DefId` of const
parameters from block that resolve to a const parameter (as well as
const parameters directly, as it was previously).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.