Skip to content

Commit

Permalink
Add assert to check if tcx.sess has errors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JulianKnodt committed Aug 4, 2020
1 parent d08eb98 commit b134975
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
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
25 changes: 25 additions & 0 deletions src/test/ui/const-generics/issue-74634.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#![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> {}

0 comments on commit b134975

Please sign in to comment.