From c411bea2e20d0366d7a877727ddef3e69cf3f9a0 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Fri, 17 Feb 2023 10:07:03 -0700 Subject: [PATCH] fix ice in generic_const_exprs --- compiler/rustc_middle/src/ty/consts.rs | 5 +-- .../generic_const_exprs/issue-108165.rs | 10 +++++ .../generic_const_exprs/issue-108165.stderr | 40 +++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 tests/ui/const-generics/generic_const_exprs/issue-108165.rs create mode 100644 tests/ui/const-generics/generic_const_exprs/issue-108165.stderr diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 08e2ef0cadab7..26de16e4ddae0 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -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, diff --git a/tests/ui/const-generics/generic_const_exprs/issue-108165.rs b/tests/ui/const-generics/generic_const_exprs/issue-108165.rs new file mode 100644 index 0000000000000..409aad298068d --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/issue-108165.rs @@ -0,0 +1,10 @@ +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +pub trait TraitWAssocConst { + const A: dyn TraitWAssocConst; //~ ERROR: associated const equality is incomplete + //~^ ERROR: cycle detected when computing type +} + +fn main>() {} +//~^ ERROR: associated const equality is incomplete diff --git a/tests/ui/const-generics/generic_const_exprs/issue-108165.stderr b/tests/ui/const-generics/generic_const_exprs/issue-108165.stderr new file mode 100644 index 0000000000000..c67ca793bcc7f --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/issue-108165.stderr @@ -0,0 +1,40 @@ +error[E0658]: associated const equality is incomplete + --> $DIR/issue-108165.rs:5:35 + | +LL | const A: dyn TraitWAssocConst; + | ^^^ + | + = note: see issue #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>() {} + | ^^^ + | + = note: see issue #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; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: ...which requires computing type of `TraitWAssocConst::A::{constant#0}`... + --> $DIR/issue-108165.rs:5:37 + | +LL | const A: dyn TraitWAssocConst; + | ^ + = 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>() {} + | ^ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0391, E0658. +For more information about an error, try `rustc --explain E0391`.