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

davidtwco
Copy link
Member

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

r? @varkor

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 9, 2019
src/librustc_typeck/check/mod.rs Outdated Show resolved Hide resolved
//~^ 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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@varkor varkor Jun 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

src/librustc_typeck/check/mod.rs Show resolved Hide resolved
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).
@varkor
Copy link
Member

varkor commented Jun 10, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Jun 10, 2019

📌 Commit 9ed4674 has been approved by varkor

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 10, 2019
Centril added a commit to Centril/rust that referenced this pull request Jun 11, 2019
… 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
… 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
… 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
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
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
@davidtwco davidtwco deleted the ice-const-generic-length branch June 12, 2019 06:26
davidtwco added a commit to davidtwco/rust that referenced this pull request Jun 13, 2019
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
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Broken MIR" ICE while creating array with const generic length from single value
6 participants