Added initial processing of UserAssertTy statements.
This commit is contained in:
parent
1331cd4a8c
commit
5f21aa8734
3 changed files with 40 additions and 17 deletions
|
|
@ -761,12 +761,27 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
|
|||
);
|
||||
};
|
||||
}
|
||||
StatementKind::UserAssertTy(ref ty, ref local) => {
|
||||
let local_ty = mir.local_decls()[*local].ty;
|
||||
debug!("check_stmt: user_assert_ty ty={:?} local_ty={:?}", ty, local_ty);
|
||||
if let Err(terr) =
|
||||
self.eq_types(ty, local_ty, location.at_successor_within_block())
|
||||
{
|
||||
span_mirbug!(
|
||||
self,
|
||||
stmt,
|
||||
"bad type assert ({:?} = {:?}): {:?}",
|
||||
ty,
|
||||
local_ty,
|
||||
terr
|
||||
);
|
||||
}
|
||||
}
|
||||
StatementKind::StorageLive(_)
|
||||
| StatementKind::StorageDead(_)
|
||||
| StatementKind::InlineAsm { .. }
|
||||
| StatementKind::EndRegion(_)
|
||||
| StatementKind::Validate(..)
|
||||
| StatementKind::UserAssertTy(..)
|
||||
| StatementKind::Nop => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ use rustc::mir::visit::{MutVisitor, Visitor, TyContext};
|
|||
use rustc::ty::{Ty, RegionKind, TyCtxt};
|
||||
use transform::{MirPass, MirSource};
|
||||
|
||||
pub struct CleanupPostBorrowck;
|
||||
pub struct CleanEndRegions;
|
||||
|
||||
struct GatherBorrowedRegions {
|
||||
seen_regions: FxHashSet<region::Scope>,
|
||||
|
|
@ -48,24 +48,19 @@ struct DeleteTrivialEndRegions<'a> {
|
|||
seen_regions: &'a FxHashSet<region::Scope>,
|
||||
}
|
||||
|
||||
pub struct DeleteUserAssertTy;
|
||||
|
||||
impl MirPass for CleanupPostBorrowck {
|
||||
impl MirPass for CleanEndRegions {
|
||||
fn run_pass<'a, 'tcx>(&self,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
_source: MirSource,
|
||||
mir: &mut Mir<'tcx>) {
|
||||
if tcx.emit_end_regions() {
|
||||
let mut gather = GatherBorrowedRegions {
|
||||
seen_regions: FxHashSet()
|
||||
};
|
||||
gather.visit_mir(mir);
|
||||
if !tcx.emit_end_regions() { return; }
|
||||
|
||||
let mut delete = DeleteTrivialEndRegions { seen_regions: &mut gather.seen_regions };
|
||||
delete.visit_mir(mir);
|
||||
}
|
||||
let mut gather = GatherBorrowedRegions {
|
||||
seen_regions: FxHashSet()
|
||||
};
|
||||
gather.visit_mir(mir);
|
||||
|
||||
let mut delete = DeleteUserAssertTy;
|
||||
let mut delete = DeleteTrivialEndRegions { seen_regions: &mut gather.seen_regions };
|
||||
delete.visit_mir(mir);
|
||||
}
|
||||
}
|
||||
|
|
@ -115,6 +110,20 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DeleteTrivialEndRegions<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct CleanUserAssertTy;
|
||||
|
||||
pub struct DeleteUserAssertTy;
|
||||
|
||||
impl MirPass for CleanUserAssertTy {
|
||||
fn run_pass<'a, 'tcx>(&self,
|
||||
_tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
_source: MirSource,
|
||||
mir: &mut Mir<'tcx>) {
|
||||
let mut delete = DeleteUserAssertTy;
|
||||
delete.visit_mir(mir);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> MutVisitor<'tcx> for DeleteUserAssertTy {
|
||||
fn visit_statement(&mut self,
|
||||
block: BasicBlock,
|
||||
|
|
|
|||
|
|
@ -192,9 +192,8 @@ fn mir_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Stea
|
|||
|
||||
let mut mir = tcx.mir_built(def_id).steal();
|
||||
run_passes![tcx, mir, def_id, 0;
|
||||
// Remove all `UserAssertTy` statements and all `EndRegion` statements that are not
|
||||
// involved in borrows.
|
||||
cleanup_post_borrowck::CleanupPostBorrowck,
|
||||
// Remove all `EndRegion` statements that are not involved in borrows.
|
||||
cleanup_post_borrowck::CleanEndRegions,
|
||||
|
||||
// What we need to do constant evaluation.
|
||||
simplify::SimplifyCfg::new("initial"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue