Skip to content

Commit c62bc31

Browse files
committed
Fix ICE on invalid const param types
1 parent 3a36386 commit c62bc31

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

compiler/rustc_hir_analysis/src/collect.rs

+2
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
386386

387387
fn ct_infer(&self, ty: Ty<'tcx>, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> {
388388
let ty = self.tcx.fold_regions(ty, |r, _| match *r {
389+
rustc_type_ir::RegionKind::ReStatic => r,
390+
389391
// This is never reached in practice. If it ever is reached,
390392
// `ReErased` should be changed to `ReStatic`, and any other region
391393
// left alone.

tests/crashes/123863.rs

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const fn concat_strs<const A: &'static str>() -> &'static str {
2+
//~^ ERROR &'static str` is forbidden as the type of a const generic parameter
3+
struct Inner<const A: &'static str>;
4+
//~^ ERROR &'static str` is forbidden as the type of a const generic parameter
5+
Inner::concat_strs::<"a">::A
6+
//~^ ERROR ambiguous associated type
7+
}
8+
9+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: `&'static str` is forbidden as the type of a const generic parameter
2+
--> $DIR/ice-unexpected-region-123863.rs:1:31
3+
|
4+
LL | const fn concat_strs<const A: &'static str>() -> &'static str {
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: the only supported types are integers, `bool` and `char`
8+
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
9+
|
10+
LL + #![feature(adt_const_params)]
11+
|
12+
13+
error: `&'static str` is forbidden as the type of a const generic parameter
14+
--> $DIR/ice-unexpected-region-123863.rs:3:27
15+
|
16+
LL | struct Inner<const A: &'static str>;
17+
| ^^^^^^^^^^^^
18+
|
19+
= note: the only supported types are integers, `bool` and `char`
20+
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
21+
|
22+
LL + #![feature(adt_const_params)]
23+
|
24+
25+
error[E0223]: ambiguous associated type
26+
--> $DIR/ice-unexpected-region-123863.rs:5:5
27+
|
28+
LL | Inner::concat_strs::<"a">::A
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
30+
|
31+
help: if there were a trait named `Example` with associated type `concat_strs` implemented for `Inner<_>`, you could use the fully-qualified path
32+
|
33+
LL | <Inner<_> as Example>::concat_strs::A
34+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35+
36+
error: aborting due to 3 previous errors
37+
38+
For more information about this error, try `rustc --explain E0223`.

0 commit comments

Comments
 (0)