use rustc::middle::expr_use_visitor as euv;
use rustc::middle::mem_categorization as mc;
use rustc::middle::mem_categorization::Categorization;
-use rustc::middle::region::extent_has_yield;
use rustc::middle::region;
use rustc::ty::{self, TyCtxt};
mod move_error;
pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
- body_id: hir::BodyId)
+ body: hir::BodyId)
-> (Vec<Loan<'tcx>>, move_data::MoveData<'tcx>) {
- let def_id = bccx.tcx.hir.body_owner_def_id(body_id);
+ let def_id = bccx.tcx.hir.body_owner_def_id(body);
let param_env = bccx.tcx.param_env(def_id);
- let body = bccx.tcx.hir.body(body_id);
let mut glcx = GatherLoanCtxt {
bccx: bccx,
all_loans: Vec::new(),
- item_ub: region::CodeExtent::Misc(body_id.node_id),
+ item_ub: region::CodeExtent::Misc(body.node_id),
move_data: MoveData::new(),
move_error_collector: move_error::MoveErrorCollector::new(),
- generator: body.is_generator(),
};
+ let body = glcx.bccx.tcx.hir.body(body);
euv::ExprUseVisitor::new(&mut glcx, bccx.tcx, param_env, &bccx.region_maps, bccx.tables)
.consume_body(body);
/// `item_ub` is used as an upper-bound on the lifetime whenever we
/// ask for the scope of an expression categorized as an upvar.
item_ub: region::CodeExtent,
- generator: bool,
}
impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
}
}
-fn check_yields<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
- borrow_span: Span,
- loan_region: ty::Region<'tcx>) {
- if let &ty::RegionKind::ReScope(extent) = loan_region {
- if extent_has_yield(bccx.tcx, extent) {
- span_err!(bccx.tcx.sess,
- borrow_span,
- E0624,
- "cannot borrow this value across the suspend point of a generator");
- }
- }
-}
-
/// Implements the M-* rules in README.md.
fn check_mutability<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
borrow_span: Span,
return;
}
- // Check that the region has no yields if this is in a generator
- if self.generator {
- check_yields(self.bccx, borrow_span, loan_region);
- }
-
// Check that the lifetime of the borrow does not exceed
// the lifetime of the data being borrowed.
if lifetime::guarantee_lifetime(self.bccx, self.item_ub,