Skip to content
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

Fix ICE on invalid const param types #124394

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
@@ -386,6 +386,8 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {

fn ct_infer(&self, ty: Ty<'tcx>, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> {
let ty = self.tcx.fold_regions(ty, |r, _| match *r {
rustc_type_ir::RegionKind::ReStatic => r,

// This is never reached in practice. If it ever is reached,
// `ReErased` should be changed to `ReStatic`, and any other region
// left alone.
6 changes: 0 additions & 6 deletions tests/crashes/123863.rs

This file was deleted.

9 changes: 9 additions & 0 deletions tests/ui/typeck/ice-unexpected-region-123863.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fn concat_strs<const A: &'static str>() -> &'static str {
//~^ ERROR &'static str` is forbidden as the type of a const generic parameter
struct Inner<const A: &'static str>;
//~^ ERROR &'static str` is forbidden as the type of a const generic parameter
Inner::concat_strs::<"a">::A
//~^ ERROR ambiguous associated type
}

pub fn main() {}
38 changes: 38 additions & 0 deletions tests/ui/typeck/ice-unexpected-region-123863.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
error: `&'static str` is forbidden as the type of a const generic parameter
--> $DIR/ice-unexpected-region-123863.rs:1:31
|
LL | const fn concat_strs<const A: &'static str>() -> &'static str {
| ^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
|

error: `&'static str` is forbidden as the type of a const generic parameter
--> $DIR/ice-unexpected-region-123863.rs:3:27
|
LL | struct Inner<const A: &'static str>;
| ^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
|

error[E0223]: ambiguous associated type
--> $DIR/ice-unexpected-region-123863.rs:5:5
|
LL | Inner::concat_strs::<"a">::A
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: if there were a trait named `Example` with associated type `concat_strs` implemented for `Inner<_>`, you could use the fully-qualified path
|
LL | <Inner<_> as Example>::concat_strs::A
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0223`.