Skip to content

Commit e018fc3

Browse files
author
Cameron Zwarich
committed
Remove Restriction
The Restriction struct now consists of a single Rc<LoanPath> field, so it can be replaced with Rc<LoanPath>.
1 parent 59309e0 commit e018fc3

File tree

4 files changed

+11
-21
lines changed

4 files changed

+11
-21
lines changed

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ impl<'a> CheckLoanCtxt<'a> {
208208
loan.repr(self.tcx()));
209209

210210
let mut ret = true;
211-
for restr in loan.restrictions.iter() {
212-
if *restr.loan_path == *loan_path {
211+
for restr_path in loan.restricted_paths.iter() {
212+
if **restr_path == *loan_path {
213213
if !op(loan) {
214214
ret = false;
215215
break;
@@ -298,8 +298,8 @@ impl<'a> CheckLoanCtxt<'a> {
298298
return true;
299299
}
300300

301-
for restr in loan1.restrictions.iter() {
302-
if restr.loan_path != loan2.loan_path { continue; }
301+
for restr_path in loan1.restricted_paths.iter() {
302+
if *restr_path != loan2.loan_path { continue; }
303303

304304
let old_pronoun = if new_loan.loan_path == old_loan.loan_path {
305305
"it".to_string()

src/librustc/middle/borrowck/gather_loans/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl<'a> GatherLoanCtxt<'a> {
268268
return;
269269
}
270270

271-
restrictions::SafeIf(loan_path, restrictions) => {
271+
restrictions::SafeIf(loan_path, restricted_paths) => {
272272
let loan_scope = match loan_region {
273273
ty::ReScope(id) => id,
274274
ty::ReFree(ref fr) => fr.scope_id,
@@ -314,7 +314,7 @@ impl<'a> GatherLoanCtxt<'a> {
314314
gen_scope: gen_scope,
315315
kill_scope: kill_scope,
316316
span: borrow_span,
317-
restrictions: restrictions,
317+
restricted_paths: restricted_paths,
318318
cause: cause,
319319
}
320320
}

src/librustc/middle/borrowck/gather_loans/restrictions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::rc::Rc;
2323

2424
pub enum RestrictionResult {
2525
Safe,
26-
SafeIf(Rc<LoanPath>, Vec<Restriction>)
26+
SafeIf(Rc<LoanPath>, Vec<Rc<LoanPath>>)
2727
}
2828

2929
pub fn compute_restrictions(bccx: &BorrowckCtxt,
@@ -71,7 +71,7 @@ impl<'a> RestrictionsContext<'a> {
7171
mc::cat_upvar(ty::UpvarId {var_id: local_id, ..}, _) => {
7272
// R-Variable
7373
let lp = Rc::new(LpVar(local_id));
74-
SafeIf(lp.clone(), vec!(Restriction { loan_path: lp }))
74+
SafeIf(lp.clone(), vec!(lp))
7575
}
7676

7777
mc::cat_downcast(cmt_base) => {
@@ -164,7 +164,7 @@ impl<'a> RestrictionsContext<'a> {
164164
Safe => Safe,
165165
SafeIf(base_lp, mut base_vec) => {
166166
let lp = Rc::new(LpExtend(base_lp, mc, elem));
167-
base_vec.push(Restriction { loan_path: lp.clone() });
167+
base_vec.push(lp.clone());
168168
SafeIf(lp, base_vec)
169169
}
170170
}

src/librustc/middle/borrowck/mod.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub struct Loan {
181181
index: uint,
182182
loan_path: Rc<LoanPath>,
183183
kind: ty::BorrowKind,
184-
restrictions: Vec<Restriction>,
184+
restricted_paths: Vec<Rc<LoanPath>>,
185185
gen_scope: ast::NodeId,
186186
kill_scope: ast::NodeId,
187187
span: Span,
@@ -249,10 +249,6 @@ pub fn opt_loan_path(cmt: &mc::cmt) -> Option<Rc<LoanPath>> {
249249
}
250250
}
251251

252-
pub struct Restriction {
253-
loan_path: Rc<LoanPath>,
254-
}
255-
256252
///////////////////////////////////////////////////////////////////////////
257253
// Errors
258254

@@ -777,13 +773,7 @@ impl Repr for Loan {
777773
self.kind,
778774
self.gen_scope,
779775
self.kill_scope,
780-
self.restrictions.repr(tcx))).to_string()
781-
}
782-
}
783-
784-
impl Repr for Restriction {
785-
fn repr(&self, tcx: &ty::ctxt) -> String {
786-
(format!("Restriction({})", self.loan_path.repr(tcx))).to_string()
776+
self.restricted_paths.repr(tcx))).to_string()
787777
}
788778
}
789779

0 commit comments

Comments
 (0)