Skip to content

Commit

Permalink
Rollup merge of #30392 - Ms2ger:RestrictionResult, r=alexcrichton
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Dec 16, 2015
2 parents 6ec0c75 + 9a0ab50 commit 780bdaa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/librustc_borrowck/borrowck/gather_loans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ use rustc_front::hir::Expr;
use rustc_front::intravisit;
use rustc_front::intravisit::Visitor;

use self::restrictions::RestrictionResult;

mod lifetime;
mod restrictions;
mod gather_moves;
Expand Down Expand Up @@ -354,12 +356,12 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {

// Create the loan record (if needed).
let loan = match restr {
restrictions::Safe => {
RestrictionResult::Safe => {
// No restrictions---no loan record necessary
return;
}

restrictions::SafeIf(loan_path, restricted_paths) => {
RestrictionResult::SafeIf(loan_path, restricted_paths) => {
let loan_scope = match loan_region {
ty::ReScope(scope) => scope,

Expand Down
22 changes: 10 additions & 12 deletions src/librustc_borrowck/borrowck/gather_loans/restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

//! Computes the restrictions that result from a borrow.
pub use self::RestrictionResult::*;

use borrowck::*;
use rustc::middle::expr_use_visitor as euv;
use rustc::middle::mem_categorization as mc;
Expand Down Expand Up @@ -69,19 +67,19 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
// are inherently non-aliasable, they can only be
// accessed later through the borrow itself and hence
// must inherently comply with its terms.
Safe
RestrictionResult::Safe
}

Categorization::Local(local_id) => {
// R-Variable, locally declared
let lp = new_lp(LpVar(local_id));
SafeIf(lp.clone(), vec![lp])
RestrictionResult::SafeIf(lp.clone(), vec![lp])
}

Categorization::Upvar(mc::Upvar { id, .. }) => {
// R-Variable, captured into closure
let lp = new_lp(LpUpvar(id));
SafeIf(lp.clone(), vec![lp])
RestrictionResult::SafeIf(lp.clone(), vec![lp])
}

Categorization::Downcast(cmt_base, _) => {
Expand All @@ -106,7 +104,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
}

Categorization::StaticItem => {
Safe
RestrictionResult::Safe
}

Categorization::Deref(cmt_base, _, pk) => {
Expand All @@ -133,11 +131,11 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
cmt: cmt_base,
code: err_borrowed_pointer_too_short(
self.loan_region, lt)});
return Safe;
return RestrictionResult::Safe;
}

match bk {
ty::ImmBorrow => Safe,
ty::ImmBorrow => RestrictionResult::Safe,
ty::MutBorrow | ty::UniqueImmBorrow => {
// R-Deref-Mut-Borrowed
//
Expand All @@ -150,7 +148,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
}
}
// Borrowck is not relevant for raw pointers
mc::UnsafePtr(..) => Safe
mc::UnsafePtr(..) => RestrictionResult::Safe
}
}
}
Expand All @@ -161,12 +159,12 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
cmt: &mc::cmt<'tcx>,
elem: LoanPathElem) -> RestrictionResult<'tcx> {
match result {
Safe => Safe,
SafeIf(base_lp, mut base_vec) => {
RestrictionResult::Safe => RestrictionResult::Safe,
RestrictionResult::SafeIf(base_lp, mut base_vec) => {
let v = LpExtend(base_lp, cmt.mutbl, elem);
let lp = Rc::new(LoanPath::new(v, cmt.ty));
base_vec.push(lp.clone());
SafeIf(lp, base_vec)
RestrictionResult::SafeIf(lp, base_vec)
}
}
}
Expand Down

0 comments on commit 780bdaa

Please sign in to comment.