Skip to content

Commit 5f21aa8

Browse files
committed
Added initial processing of UserAssertTy statements.
1 parent 1331cd4 commit 5f21aa8

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,12 +761,27 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
761761
);
762762
};
763763
}
764+
StatementKind::UserAssertTy(ref ty, ref local) => {
765+
let local_ty = mir.local_decls()[*local].ty;
766+
debug!("check_stmt: user_assert_ty ty={:?} local_ty={:?}", ty, local_ty);
767+
if let Err(terr) =
768+
self.eq_types(ty, local_ty, location.at_successor_within_block())
769+
{
770+
span_mirbug!(
771+
self,
772+
stmt,
773+
"bad type assert ({:?} = {:?}): {:?}",
774+
ty,
775+
local_ty,
776+
terr
777+
);
778+
}
779+
}
764780
StatementKind::StorageLive(_)
765781
| StatementKind::StorageDead(_)
766782
| StatementKind::InlineAsm { .. }
767783
| StatementKind::EndRegion(_)
768784
| StatementKind::Validate(..)
769-
| StatementKind::UserAssertTy(..)
770785
| StatementKind::Nop => {}
771786
}
772787
}

src/librustc_mir/transform/cleanup_post_borrowck.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use rustc::mir::visit::{MutVisitor, Visitor, TyContext};
3838
use rustc::ty::{Ty, RegionKind, TyCtxt};
3939
use transform::{MirPass, MirSource};
4040

41-
pub struct CleanupPostBorrowck;
41+
pub struct CleanEndRegions;
4242

4343
struct GatherBorrowedRegions {
4444
seen_regions: FxHashSet<region::Scope>,
@@ -48,24 +48,19 @@ struct DeleteTrivialEndRegions<'a> {
4848
seen_regions: &'a FxHashSet<region::Scope>,
4949
}
5050

51-
pub struct DeleteUserAssertTy;
52-
53-
impl MirPass for CleanupPostBorrowck {
51+
impl MirPass for CleanEndRegions {
5452
fn run_pass<'a, 'tcx>(&self,
5553
tcx: TyCtxt<'a, 'tcx, 'tcx>,
5654
_source: MirSource,
5755
mir: &mut Mir<'tcx>) {
58-
if tcx.emit_end_regions() {
59-
let mut gather = GatherBorrowedRegions {
60-
seen_regions: FxHashSet()
61-
};
62-
gather.visit_mir(mir);
63-
64-
let mut delete = DeleteTrivialEndRegions { seen_regions: &mut gather.seen_regions };
65-
delete.visit_mir(mir);
66-
}
56+
if !tcx.emit_end_regions() { return; }
6757

68-
let mut delete = DeleteUserAssertTy;
58+
let mut gather = GatherBorrowedRegions {
59+
seen_regions: FxHashSet()
60+
};
61+
gather.visit_mir(mir);
62+
63+
let mut delete = DeleteTrivialEndRegions { seen_regions: &mut gather.seen_regions };
6964
delete.visit_mir(mir);
7065
}
7166
}
@@ -115,6 +110,20 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DeleteTrivialEndRegions<'a> {
115110
}
116111
}
117112

113+
pub struct CleanUserAssertTy;
114+
115+
pub struct DeleteUserAssertTy;
116+
117+
impl MirPass for CleanUserAssertTy {
118+
fn run_pass<'a, 'tcx>(&self,
119+
_tcx: TyCtxt<'a, 'tcx, 'tcx>,
120+
_source: MirSource,
121+
mir: &mut Mir<'tcx>) {
122+
let mut delete = DeleteUserAssertTy;
123+
delete.visit_mir(mir);
124+
}
125+
}
126+
118127
impl<'tcx> MutVisitor<'tcx> for DeleteUserAssertTy {
119128
fn visit_statement(&mut self,
120129
block: BasicBlock,

src/librustc_mir/transform/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,8 @@ fn mir_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Stea
192192

193193
let mut mir = tcx.mir_built(def_id).steal();
194194
run_passes![tcx, mir, def_id, 0;
195-
// Remove all `UserAssertTy` statements and all `EndRegion` statements that are not
196-
// involved in borrows.
197-
cleanup_post_borrowck::CleanupPostBorrowck,
195+
// Remove all `EndRegion` statements that are not involved in borrows.
196+
cleanup_post_borrowck::CleanEndRegions,
198197

199198
// What we need to do constant evaluation.
200199
simplify::SimplifyCfg::new("initial"),

0 commit comments

Comments
 (0)