Fix ICE with struct ctors and const generics.

This commit fixes a ICE where struct constructors were resulting in an
ICE with const generics. Previously, a `match` in `type_of` did not have
an arm for the `DefKind::Ctor` resolutions and therefore would assume
that the type did not have generics.
This commit is contained in:
David Wood 2019-05-14 21:34:43 +01:00
parent 4b9d80325a
commit 41aaf7bc46
No known key found for this signature in database
GPG key ID: 01760B4F9F53F154
6 changed files with 74 additions and 73 deletions

View file

@ -1,8 +1,9 @@
// compile-pass
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
// We should probably be able to infer the types here. However, this test is checking that we don't
// get an ICE in this case. It may be modified later to not be an error.
// This test confirms that the types can be inferred correctly for this example with const
// generics. Previously this would ICE, and more recently error.
struct Foo<const NUM_BYTES: usize>(pub [u8; NUM_BYTES]);

View file

@ -1,25 +1,6 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/cannot-infer-type-for-const-param.rs:1:12
--> $DIR/cannot-infer-type-for-const-param.rs:2:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
error[E0282]: type annotations needed
--> $DIR/cannot-infer-type-for-const-param.rs:10:19
|
LL | let _ = Foo::<3>([1, 2, 3]);
| ^ cannot infer type for `{integer}`
error[E0308]: mismatched types
--> $DIR/cannot-infer-type-for-const-param.rs:10:22
|
LL | let _ = Foo::<3>([1, 2, 3]);
| ^^^^^^^^^ expected `3`, found `3usize`
|
= note: expected type `[u8; _]`
found type `[u8; 3]`
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0282, E0308.
For more information about an error, try `rustc --explain E0282`.

View file

@ -0,0 +1,10 @@
// compile-pass
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
struct Generic<const V: usize>;
fn main() {
let _ = Generic::<0>;
}

View file

@ -0,0 +1,6 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/issue-60818-struct-constructors.rs:3:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^