Skip to content

Commit 3e247a8

Browse files
committed
Add regression test for const parameter default ICE
1 parent 3bf5c6d commit 3e247a8

2 files changed

Lines changed: 48 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/142913.
2+
3+
// A const parameter introduced by `generic_const_parameter_types`,
4+
// whose type mentions an earlier lifetime
5+
// parameter and which carries a default value, used to ICE in `rustc_type_ir`
6+
// with "region parameter out of range when instantiating args". It is now
7+
// rejected with ordinary errors instead of crashing.
8+
9+
#![feature(generic_const_parameter_types)]
10+
11+
struct Variant;
12+
13+
fn foo<'a, const N: &'a Variant = {}>() {}
14+
//~^ ERROR: defaults for generic parameters are not allowed here
15+
//~| ERROR: anonymous constants with lifetimes in their type are not yet supported
16+
//~| ERROR: `&'a Variant` is forbidden as the type of a const generic parameter
17+
18+
fn main() {}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error: defaults for generic parameters are not allowed here
2+
--> $DIR/lifetime_dependent_const_param_default.rs:13:12
3+
|
4+
LL | fn foo<'a, const N: &'a Variant = {}>() {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: anonymous constants with lifetimes in their type are not yet supported
8+
--> $DIR/lifetime_dependent_const_param_default.rs:13:35
9+
|
10+
LL | fn foo<'a, const N: &'a Variant = {}>() {}
11+
| ^^
12+
13+
error: `&'a Variant` is forbidden as the type of a const generic parameter
14+
--> $DIR/lifetime_dependent_const_param_default.rs:13:21
15+
|
16+
LL | fn foo<'a, const N: &'a Variant = {}>() {}
17+
| ^^^^^^^^^^^
18+
|
19+
= note: the only supported types are integers, `bool`, and `char`
20+
help: add `#![feature(min_adt_const_params)]` to the crate attributes to enable more complex and user defined types
21+
|
22+
LL + #![feature(min_adt_const_params)]
23+
|
24+
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
25+
|
26+
LL + #![feature(unsized_const_params)]
27+
|
28+
29+
error: aborting due to 3 previous errors
30+

0 commit comments

Comments
 (0)