From b1349752c53874595772c1a175055f296a32a609 Mon Sep 17 00:00:00 2001 From: kadmin Date: Tue, 4 Aug 2020 20:16:18 +0000 Subject: [PATCH 1/2] Add assert to check if tcx.sess has errors This checks when trait bounds are introduced if the tcx.session has errors, not sure if this where the problem could come from but might as well look --- src/librustc_traits/chalk/db.rs | 8 +++++--- src/test/ui/const-generics/issue-74634.rs | 25 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/const-generics/issue-74634.rs 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/issue-74634.rs b/src/test/ui/const-generics/issue-74634.rs new file mode 100644 index 0000000000000..1dd5bea306aa5 --- /dev/null +++ b/src/test/ui/const-generics/issue-74634.rs @@ -0,0 +1,25 @@ +#![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 {} From f7cebac0aca6fead931f1236a2b42094263def28 Mon Sep 17 00:00:00 2001 From: kadmin Date: Tue, 4 Aug 2020 20:46:27 +0000 Subject: [PATCH 2/2] Add even more asserts --- src/librustc_middle/infer/canonical.rs | 8 +++++--- src/librustc_middle/ty/fold.rs | 2 ++ src/test/ui/const-generics/{ => issues}/issue-74634.rs | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) rename src/test/ui/const-generics/{ => issues}/issue-74634.rs (97%) 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/test/ui/const-generics/issue-74634.rs b/src/test/ui/const-generics/issues/issue-74634.rs similarity index 97% rename from src/test/ui/const-generics/issue-74634.rs rename to src/test/ui/const-generics/issues/issue-74634.rs index 1dd5bea306aa5..30ab291155c91 100644 --- a/src/test/ui/const-generics/issue-74634.rs +++ b/src/test/ui/const-generics/issues/issue-74634.rs @@ -23,3 +23,5 @@ where (): IsZero {} impl Foobar for () where (): IsZero {} + +fn main() {}