diff --git a/src/librustc_middle/infer/canonical.rs b/src/librustc_middle/infer/canonical.rs index 9433d282ad297..b4157e66c1665 100644 --- a/src/librustc_middle/infer/canonical.rs +++ b/src/librustc_middle/infer/canonical.rs @@ -327,12 +327,14 @@ impl<'tcx> CanonicalVarValues<'tcx> { GenericArgKind::Lifetime(..) => tcx .mk_region(ty::ReLateBound(ty::INNERMOST, ty::BoundRegion::BrAnon(i))) .into(), - GenericArgKind::Const(ct) => tcx - .mk_const(ty::Const { + GenericArgKind::Const(ct) => { + assert!(!tcx.sess.has_errors()); + tcx.mk_const(ty::Const { ty: ct.ty, val: ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i)), }) - .into(), + .into() + } }) .collect(), } diff --git a/src/librustc_middle/ty/fold.rs b/src/librustc_middle/ty/fold.rs index 492f8ce9ef1a9..c34a9cf8d61ed 100644 --- a/src/librustc_middle/ty/fold.rs +++ b/src/librustc_middle/ty/fold.rs @@ -556,6 +556,7 @@ impl<'tcx> TyCtxt<'tcx> { // identity for bound types and consts let fld_t = |bound_ty| self.mk_ty(ty::Bound(ty::INNERMOST, bound_ty)); let fld_c = |bound_ct, ty| { + assert!(!self.sess.has_errors()); self.mk_const(ty::Const { val: ty::ConstKind::Bound(ty::INNERMOST, bound_ct), ty }) }; self.replace_escaping_bound_vars(value.as_ref().skip_binder(), fld_r, fld_t, fld_c) @@ -803,6 +804,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> { debruijn.shifted_out(self.amount) } }; + assert!(!self.tcx.sess.has_errors()); self.tcx.mk_const(ty::Const { val: ty::ConstKind::Bound(debruijn, bound_ct), ty }) } } else { diff --git a/src/librustc_traits/chalk/db.rs b/src/librustc_traits/chalk/db.rs index 715e5299a37bd..9cce8edf177d5 100644 --- a/src/librustc_traits/chalk/db.rs +++ b/src/librustc_traits/chalk/db.rs @@ -560,12 +560,14 @@ fn bound_vars_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> { )) .into(), - ty::GenericParamDefKind::Const => tcx - .mk_const(ty::Const { + ty::GenericParamDefKind::Const => { + assert!(!tcx.sess.has_errors()); + tcx.mk_const(ty::Const { val: ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from(param.index)), ty: tcx.type_of(param.def_id), }) - .into(), + .into() + } }) } diff --git a/src/test/ui/const-generics/issues/issue-74634.rs b/src/test/ui/const-generics/issues/issue-74634.rs new file mode 100644 index 0000000000000..30ab291155c91 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-74634.rs @@ -0,0 +1,27 @@ +#![feature(const_generics)] +#![allow(incomplete_features)] + +trait If {} +impl If for () {} + +trait IsZero { + type Answer; +} + +struct True; +struct False; + +impl IsZero for () +where (): If<{N == 0}> { + type Answer = True; +} + +trait Foobar {} + +impl Foobar for () +where (): IsZero {} + +impl Foobar for () +where (): IsZero {} + +fn main() {}