-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Conversation
0efc78c
to
cdcb7e6
Compare
cdcb7e6
to
2a3e004
Compare
//~^ 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] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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).
2a3e004
to
9ed4674
Compare
@bors r+ |
📌 Commit 9ed4674 has been approved by |
… 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
… 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
… 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
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
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
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).
Fixes #61336. Turns out this wasn't related to #49147 after all.
r? @varkor