Skip to content

Commit 4ab473a

Browse files
author
Cameron Zwarich
committed
---
yaml --- r: 152584 b: refs/heads/try2 c: 59309e0 h: refs/heads/master v: v3
1 parent 52fd3e4 commit 4ab473a

File tree

4 files changed

+18
-99
lines changed

4 files changed

+18
-99
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 99347591956958ab62074a41a83b4a62587c2ee6
8+
refs/heads/try2: 59309e0d9bf3eba0f4219062b451ff10cbdf0e2b
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<'a> GatherLoanCtxt<'a> {
259259
// loan is safe.
260260
let restr = restrictions::compute_restrictions(
261261
self.bccx, borrow_span, cause,
262-
cmt.clone(), loan_region, self.restriction_set(req_kind));
262+
cmt.clone(), loan_region);
263263

264264
// Create the loan record (if needed).
265265
let loan = match restr {
@@ -390,21 +390,6 @@ impl<'a> GatherLoanCtxt<'a> {
390390
}
391391
}
392392

393-
fn restriction_set(&self, req_kind: ty::BorrowKind) -> RestrictionSet {
394-
match req_kind {
395-
// If borrowing data as immutable, no mutation allowed:
396-
ty::ImmBorrow => RESTR_MUTATE,
397-
398-
// If borrowing data as mutable, no mutation nor other
399-
// borrows allowed:
400-
ty::MutBorrow => RESTR_MUTATE | RESTR_FREEZE,
401-
402-
// If borrowing data as unique imm, no mutation nor other
403-
// borrows allowed:
404-
ty::UniqueImmBorrow => RESTR_MUTATE | RESTR_FREEZE,
405-
}
406-
}
407-
408393
pub fn mark_loan_path_as_mutated(&self, loan_path: &LoanPath) {
409394
//! For mutable loans of content whose mutability derives
410395
//! from a local variable, mark the mutability decl as necessary.

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

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,15 @@ pub fn compute_restrictions(bccx: &BorrowckCtxt,
3030
span: Span,
3131
cause: euv::LoanCause,
3232
cmt: mc::cmt,
33-
loan_region: ty::Region,
34-
restr: RestrictionSet) -> RestrictionResult {
33+
loan_region: ty::Region) -> RestrictionResult {
3534
let ctxt = RestrictionsContext {
3635
bccx: bccx,
3736
span: span,
3837
cause: cause,
3938
loan_region: loan_region,
4039
};
4140

42-
ctxt.restrict(cmt, restr)
41+
ctxt.restrict(cmt)
4342
}
4443

4544
///////////////////////////////////////////////////////////////////////////
@@ -54,11 +53,8 @@ struct RestrictionsContext<'a> {
5453

5554
impl<'a> RestrictionsContext<'a> {
5655
fn restrict(&self,
57-
cmt: mc::cmt,
58-
restrictions: RestrictionSet) -> RestrictionResult {
59-
debug!("restrict(cmt={}, restrictions={})",
60-
cmt.repr(self.bccx.tcx),
61-
restrictions.repr(self.bccx.tcx));
56+
cmt: mc::cmt) -> RestrictionResult {
57+
debug!("restrict(cmt={})", cmt.repr(self.bccx.tcx));
6258

6359
match cmt.cat.clone() {
6460
mc::cat_rvalue(..) => {
@@ -75,19 +71,14 @@ impl<'a> RestrictionsContext<'a> {
7571
mc::cat_upvar(ty::UpvarId {var_id: local_id, ..}, _) => {
7672
// R-Variable
7773
let lp = Rc::new(LpVar(local_id));
78-
SafeIf(lp.clone(), vec!(Restriction {
79-
loan_path: lp,
80-
set: restrictions
81-
}))
74+
SafeIf(lp.clone(), vec!(Restriction { loan_path: lp }))
8275
}
8376

8477
mc::cat_downcast(cmt_base) => {
8578
// When we borrow the interior of an enum, we have to
8679
// ensure the enum itself is not mutated, because that
8780
// could cause the type of the memory to change.
88-
self.restrict(
89-
cmt_base,
90-
restrictions | RESTR_MUTATE)
81+
self.restrict(cmt_base)
9182
}
9283

9384
mc::cat_interior(cmt_base, i) => {
@@ -96,8 +87,8 @@ impl<'a> RestrictionsContext<'a> {
9687
// Overwriting the base would not change the type of
9788
// the memory, so no additional restrictions are
9889
// needed.
99-
let result = self.restrict(cmt_base, restrictions);
100-
self.extend(result, cmt.mutbl, LpInterior(i), restrictions)
90+
let result = self.restrict(cmt_base);
91+
self.extend(result, cmt.mutbl, LpInterior(i))
10192
}
10293

10394
mc::cat_deref(cmt_base, _, pk @ mc::OwnedPtr) |
@@ -112,10 +103,8 @@ impl<'a> RestrictionsContext<'a> {
112103
// same, because this could be the last ref.
113104
// Eventually we should make these non-special and
114105
// just rely on Deref<T> implementation.
115-
let result = self.restrict(
116-
cmt_base,
117-
restrictions | RESTR_MUTATE);
118-
self.extend(result, cmt.mutbl, LpDeref(pk), restrictions)
106+
let result = self.restrict(cmt_base);
107+
self.extend(result, cmt.mutbl, LpDeref(pk))
119108
}
120109

121110
mc::cat_copied_upvar(..) | // FIXME(#2152) allow mutation of upvars
@@ -152,8 +141,8 @@ impl<'a> RestrictionsContext<'a> {
152141
return Safe;
153142
}
154143

155-
let result = self.restrict(cmt_base, restrictions);
156-
self.extend(result, cmt.mutbl, LpDeref(pk), restrictions)
144+
let result = self.restrict(cmt_base);
145+
self.extend(result, cmt.mutbl, LpDeref(pk))
157146
}
158147

159148
mc::cat_deref(_, _, mc::UnsafePtr(..)) => {
@@ -162,24 +151,20 @@ impl<'a> RestrictionsContext<'a> {
162151
}
163152

164153
mc::cat_discr(cmt_base, _) => {
165-
self.restrict(cmt_base, restrictions)
154+
self.restrict(cmt_base)
166155
}
167156
}
168157
}
169158

170159
fn extend(&self,
171160
result: RestrictionResult,
172161
mc: mc::MutabilityCategory,
173-
elem: LoanPathElem,
174-
restrictions: RestrictionSet) -> RestrictionResult {
162+
elem: LoanPathElem) -> RestrictionResult {
175163
match result {
176164
Safe => Safe,
177165
SafeIf(base_lp, mut base_vec) => {
178166
let lp = Rc::new(LpExtend(base_lp, mc, elem));
179-
base_vec.push(Restriction {
180-
loan_path: lp.clone(),
181-
set: restrictions
182-
});
167+
base_vec.push(Restriction { loan_path: lp.clone() });
183168
SafeIf(lp, base_vec)
184169
}
185170
}

branches/try2/src/librustc/middle/borrowck/mod.rs

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use middle::ty;
2121
use util::ppaux::{note_and_explain_region, Repr, UserString};
2222

2323
use std::cell::{Cell};
24-
use std::ops::{BitOr, BitAnd};
2524
use std::rc::Rc;
2625
use std::gc::{Gc, GC};
2726
use std::string::String;
@@ -250,56 +249,8 @@ pub fn opt_loan_path(cmt: &mc::cmt) -> Option<Rc<LoanPath>> {
250249
}
251250
}
252251

253-
///////////////////////////////////////////////////////////////////////////
254-
// Restrictions
255-
//
256-
// Borrowing an lvalue often results in *restrictions* that limit what
257-
// can be done with this lvalue during the scope of the loan:
258-
//
259-
// - `RESTR_MUTATE`: The lvalue may not be modified or `&mut` borrowed.
260-
// - `RESTR_FREEZE`: `&` borrows of the lvalue are forbidden.
261-
//
262-
// In addition, no value which is restricted may be moved. Therefore,
263-
// restrictions are meaningful even if the RestrictionSet is empty,
264-
// because the restriction against moves is implied.
265-
266252
pub struct Restriction {
267253
loan_path: Rc<LoanPath>,
268-
set: RestrictionSet
269-
}
270-
271-
#[deriving(PartialEq)]
272-
pub struct RestrictionSet {
273-
bits: u32
274-
}
275-
276-
#[allow(dead_code)] // potentially useful
277-
pub static RESTR_EMPTY: RestrictionSet = RestrictionSet {bits: 0b0000};
278-
pub static RESTR_MUTATE: RestrictionSet = RestrictionSet {bits: 0b0001};
279-
pub static RESTR_FREEZE: RestrictionSet = RestrictionSet {bits: 0b0010};
280-
281-
impl RestrictionSet {
282-
pub fn intersects(&self, restr: RestrictionSet) -> bool {
283-
(self.bits & restr.bits) != 0
284-
}
285-
}
286-
287-
impl BitOr<RestrictionSet,RestrictionSet> for RestrictionSet {
288-
fn bitor(&self, rhs: &RestrictionSet) -> RestrictionSet {
289-
RestrictionSet {bits: self.bits | rhs.bits}
290-
}
291-
}
292-
293-
impl BitAnd<RestrictionSet,RestrictionSet> for RestrictionSet {
294-
fn bitand(&self, rhs: &RestrictionSet) -> RestrictionSet {
295-
RestrictionSet {bits: self.bits & rhs.bits}
296-
}
297-
}
298-
299-
impl Repr for RestrictionSet {
300-
fn repr(&self, _tcx: &ty::ctxt) -> String {
301-
format!("RestrictionSet(0x{:x})", self.bits as uint)
302-
}
303254
}
304255

305256
///////////////////////////////////////////////////////////////////////////
@@ -832,9 +783,7 @@ impl Repr for Loan {
832783

833784
impl Repr for Restriction {
834785
fn repr(&self, tcx: &ty::ctxt) -> String {
835-
(format!("Restriction({}, {:x})",
836-
self.loan_path.repr(tcx),
837-
self.set.bits as uint)).to_string()
786+
(format!("Restriction({})", self.loan_path.repr(tcx))).to_string()
838787
}
839788
}
840789

0 commit comments

Comments
 (0)