Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #30409

Closed
wants to merge 15 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/librustc_borrowck/borrowck/gather_loans/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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,

22 changes: 10 additions & 12 deletions src/librustc_borrowck/borrowck/gather_loans/restrictions.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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, _) => {
@@ -106,7 +104,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
}

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

Categorization::Deref(cmt_base, _, pk) => {
@@ -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
//
@@ -150,7 +148,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
}
}
// Borrowck is not relevant for raw pointers
mc::UnsafePtr(..) => Safe
mc::UnsafePtr(..) => RestrictionResult::Safe
}
}
}
@@ -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)
}
}
}