-
Notifications
You must be signed in to change notification settings - Fork 13.4k
typeck: Fix const generic in repeat param ICE. #61698
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![feature(const_generics)] | ||
//~^ 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] | ||
//~^ ERROR array lengths can't depend on generic parameters | ||
} | ||
|
||
fn main() { | ||
let x: [u32; 5] = f::<u32, 5>(3); | ||
assert_eq!(x, [3u32; 5]); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash | ||
--> $DIR/issue-61336-1.rs:1:12 | ||
| | ||
LL | #![feature(const_generics)] | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: array lengths can't depend on generic parameters | ||
--> $DIR/issue-61336-1.rs:5:9 | ||
| | ||
LL | [x; N] | ||
| ^ | ||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#![feature(const_generics)] | ||
//~^ 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
fn g<T, const N: usize>(x: T) -> [T; N] { | ||
[x; N] | ||
//~^ ERROR the trait bound `T: std::marker::Copy` is not satisfied [E0277] | ||
} | ||
|
||
fn main() { | ||
let x: [u32; 5] = f::<u32, 5>(3); | ||
assert_eq!(x, [3u32; 5]); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash | ||
--> $DIR/issue-61336.rs:1:12 | ||
| | ||
LL | #![feature(const_generics)] | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied | ||
--> $DIR/issue-61336.rs:9:5 | ||
| | ||
LL | [x; N] | ||
| ^^^^^^ the trait `std::marker::Copy` is not implemented for `T` | ||
| | ||
= help: consider adding a `where T: std::marker::Copy` bound | ||
= note: the `Copy` trait is required because the repeated element will be copied | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
Uh oh!
There was an error while loading. Please reload this page.