Skip to content

Commit 9cee865

Browse files
committed
Add regression test for #141738
Using a struct constructor (DefKind::Ctor(Struct, Const)) as an array repeat count with `#![feature(min_generic_const_args)]` used to trigger an ICE in const alias normalization. This was fixed by PR #150704, which added const constructor support for MGCA. Add a regression test to ensure the compiler produces a proper type error instead of panicking. Closes #141738
1 parent 035b01b commit 9cee865

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Regression test for https://github.com/rust-lang/rust/issues/141738
2+
//
3+
// Using a struct constructor as an array repeat count with
4+
// `min_generic_const_args` used to ICE with "unexpected `DefKind`
5+
// for const alias to resolve to: Ctor(Struct, Const)".
6+
// It should now produce a proper type error.
7+
8+
#![feature(min_generic_const_args)]
9+
//~^ WARN the feature `min_generic_const_args` is incomplete
10+
11+
struct S
12+
where
13+
(): ;
14+
15+
fn main() {
16+
let _b = [0; S];
17+
//~^ ERROR the constant `S` is not of type `usize`
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/struct-ctor-in-array-len.rs:8:12
3+
|
4+
LL | #![feature(min_generic_const_args)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error: the constant `S` is not of type `usize`
11+
--> $DIR/struct-ctor-in-array-len.rs:16:14
12+
|
13+
LL | let _b = [0; S];
14+
| ^^^^^^ expected `usize`, found `S`
15+
|
16+
= note: the length of array `[{integer}; S]` must be type `usize`
17+
18+
error: aborting due to 1 previous error; 1 warning emitted
19+

0 commit comments

Comments
 (0)