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 const parameters cannot be generic in generic_const_exprs #108172

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions compiler/rustc_middle/src/ty/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ impl<'tcx> Const<'tcx> {
let expr = &tcx.hir().body(body_id).value;
debug!(?expr);

let ty = tcx
.type_of(def.def_id_for_type_of())
.no_bound_vars()
.expect("const parameter types cannot be generic");
let ty = tcx.type_of(def.def_id_for_type_of()).subst_identity();

match Self::try_eval_lit_or_param(tcx, ty, expr) {
Some(v) => v,
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/const-generics/generic_const_exprs/issue-108165.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

pub trait TraitWAssocConst {
const A: dyn TraitWAssocConst<A=0>; //~ ERROR: associated const equality is incomplete
//~^ ERROR: cycle detected when computing type
}

fn main<A: TraitWAssocConst<A=0>>() {}
//~^ ERROR: associated const equality is incomplete
40 changes: 40 additions & 0 deletions tests/ui/const-generics/generic_const_exprs/issue-108165.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
error[E0658]: associated const equality is incomplete
--> $DIR/issue-108165.rs:5:35
|
LL | const A: dyn TraitWAssocConst<A=0>;
| ^^^
|
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable

error[E0658]: associated const equality is incomplete
--> $DIR/issue-108165.rs:9:29
|
LL | fn main<A: TraitWAssocConst<A=0>>() {}
| ^^^
|
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable

error[E0391]: cycle detected when computing type of `TraitWAssocConst::A`
--> $DIR/issue-108165.rs:5:5
|
LL | const A: dyn TraitWAssocConst<A=0>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires computing type of `TraitWAssocConst::A::{constant#0}`...
--> $DIR/issue-108165.rs:5:37
|
LL | const A: dyn TraitWAssocConst<A=0>;
| ^
= note: ...which again requires computing type of `TraitWAssocConst::A`, completing the cycle
note: cycle used when computing type of `main::{constant#0}`
--> $DIR/issue-108165.rs:9:31
|
LL | fn main<A: TraitWAssocConst<A=0>>() {}
| ^

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0391, E0658.
For more information about an error, try `rustc --explain E0391`.