Skip to content

Commit

Permalink
rustc_mir: add sanity asserts for the types of ty::Consts.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Aug 12, 2019
1 parent c037597 commit 2882bee
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/librustc_mir/build/expr/as_constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
inferred_ty: ty,
})
});
assert_eq!(literal.ty, ty);
Constant {
span,
user_ty,
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_mir/build/matches/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}

PatternKind::Range(range) => {
assert_eq!(range.lo.ty, match_pair.pattern.ty);
assert_eq!(range.hi.ty, match_pair.pattern.ty);
Test {
span: match_pair.pattern.span,
kind: TestKind::Range(range),
Expand Down Expand Up @@ -269,6 +271,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
);
} else {
if let [success, fail] = *make_target_blocks(self) {
assert_eq!(value.ty, ty);
let expect = self.literal_operand(test.span, value);
let val = Operand::Copy(place.clone());
self.compare(block, success, fail, source_info, BinOp::Eq, expect, val);
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_mir/hair/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {

let mut kind = match (lo, hi) {
(PatternKind::Constant { value: lo }, PatternKind::Constant { value: hi }) => {
assert_eq!(lo.ty, ty);
assert_eq!(hi.ty, ty);
let cmp = compare_const_vals(
self.tcx,
lo,
Expand Down

0 comments on commit 2882bee

Please sign in to comment.