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

Investigation into #74634 #75160

Closed
wants to merge 2 commits 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
8 changes: 5 additions & 3 deletions src/librustc_middle/infer/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_middle/ty/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions src/librustc_traits/chalk/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})
}

Expand Down
27 changes: 27 additions & 0 deletions src/test/ui/const-generics/issues/issue-74634.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![feature(const_generics)]
#![allow(incomplete_features)]

trait If<const COND: bool> {}
impl If<true> for () {}

trait IsZero<const N: u8> {
type Answer;
}

struct True;
struct False;

impl<const N: u8> IsZero<N> for ()
where (): If<{N == 0}> {
type Answer = True;
}

trait Foobar<const N: u8> {}

impl<const N: u8> Foobar<N> for ()
where (): IsZero<N, Answer = True> {}

impl<const N: u8> Foobar<N> for ()
where (): IsZero<N, Answer = False> {}

fn main() {}