Skip to content

Commit fa33012

Browse files
committed
rustc: de-@ mem_categorization.
1 parent d55deae commit fa33012

File tree

9 files changed

+177
-175
lines changed

9 files changed

+177
-175
lines changed

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,9 @@ impl<'a> CheckLoanCtxt<'a> {
390390
// Mutable values can be assigned, as long as they obey loans
391391
// and aliasing restrictions:
392392
if cmt.mutbl.is_mutable() {
393-
if check_for_aliasable_mutable_writes(self, expr, cmt) {
393+
if check_for_aliasable_mutable_writes(self, expr, cmt.clone()) {
394394
if check_for_assignment_to_restricted_or_frozen_location(
395-
self, expr, cmt)
396-
{
395+
self, expr, cmt.clone()) {
397396
// Safe, but record for lint pass later:
398397
mark_variable_as_used_mut(self, cmt);
399398
}
@@ -403,9 +402,9 @@ impl<'a> CheckLoanCtxt<'a> {
403402

404403
// For immutable local variables, assignments are legal
405404
// if they cannot already have been assigned
406-
if self.is_local_variable(cmt) {
405+
if self.is_local_variable(cmt.clone()) {
407406
assert!(cmt.mutbl.is_immutable()); // no "const" locals
408-
let lp = opt_loan_path(cmt).unwrap();
407+
let lp = opt_loan_path(&cmt).unwrap();
409408
self.move_data.each_assignment_of(expr.id, &lp, |assign| {
410409
self.bccx.report_reassigned_immutable_variable(
411410
expr.span,
@@ -417,21 +416,21 @@ impl<'a> CheckLoanCtxt<'a> {
417416
}
418417

419418
// Otherwise, just a plain error.
420-
match opt_loan_path(cmt) {
419+
match opt_loan_path(&cmt) {
421420
Some(lp) => {
422421
self.bccx.span_err(
423422
expr.span,
424423
format!("cannot assign to {} {} `{}`",
425424
cmt.mutbl.to_user_str(),
426-
self.bccx.cmt_to_str(cmt),
425+
self.bccx.cmt_to_str(&*cmt),
427426
self.bccx.loan_path_to_str(&*lp)));
428427
}
429428
None => {
430429
self.bccx.span_err(
431430
expr.span,
432431
format!("cannot assign to {} {}",
433432
cmt.mutbl.to_user_str(),
434-
self.bccx.cmt_to_str(cmt)));
433+
self.bccx.cmt_to_str(&*cmt)));
435434
}
436435
}
437436
return;
@@ -448,7 +447,7 @@ impl<'a> CheckLoanCtxt<'a> {
448447
loop {
449448
debug!("mark_writes_through_upvars_as_used_mut(cmt={})",
450449
cmt.repr(this.tcx()));
451-
match cmt.cat {
450+
match cmt.cat.clone() {
452451
mc::cat_local(id) | mc::cat_arg(id) => {
453452
this.tcx().used_mut_nodes.borrow_mut().insert(id);
454453
return;
@@ -496,10 +495,10 @@ impl<'a> CheckLoanCtxt<'a> {
496495
debug!("check_for_aliasable_mutable_writes(cmt={}, guarantor={})",
497496
cmt.repr(this.tcx()), guarantor.repr(this.tcx()));
498497
match guarantor.cat {
499-
mc::cat_deref(b, _, mc::BorrowedPtr(ty::MutBorrow, _)) => {
498+
mc::cat_deref(ref b, _, mc::BorrowedPtr(ty::MutBorrow, _)) => {
500499
// Statically prohibit writes to `&mut` when aliasable
501500

502-
check_for_aliasability_violation(this, expr, b);
501+
check_for_aliasability_violation(this, expr, b.clone());
503502
}
504503

505504
_ => {}
@@ -537,7 +536,7 @@ impl<'a> CheckLoanCtxt<'a> {
537536
//! Check for assignments that violate the terms of an
538537
//! outstanding loan.
539538
540-
let loan_path = match opt_loan_path(cmt) {
539+
let loan_path = match opt_loan_path(&cmt) {
541540
Some(lp) => lp,
542541
None => { return true; /* no loan path, can't be any loans */ }
543542
};
@@ -814,7 +813,7 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,
814813
if !this.move_data.is_assignee(expr.id) {
815814
let cmt = this.bccx.cat_expr_unadjusted(expr);
816815
debug!("path cmt={}", cmt.repr(this.tcx()));
817-
for lp in opt_loan_path(cmt).iter() {
816+
for lp in opt_loan_path(&cmt).iter() {
818817
this.check_if_path_is_moved(expr.id, expr.span, MovedInUse, lp);
819818
}
820819
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ use syntax::ast;
2323
use syntax::codemap::Span;
2424
use util::ppaux::Repr;
2525

26+
use std::rc::Rc;
27+
2628
struct GatherMoveInfo {
2729
id: ast::NodeId,
2830
kind: MoveKind,
2931
cmt: mc::cmt,
3032
span_path_opt: Option<MoveSpanAndPath>
3133
}
3234

33-
use std::rc::Rc;
34-
3535
pub fn gather_decl(bccx: &BorrowckCtxt,
3636
move_data: &MoveData,
3737
decl_id: ast::NodeId,
@@ -107,7 +107,7 @@ fn gather_move(bccx: &BorrowckCtxt,
107107
move_info.id, move_info.cmt.repr(bccx.tcx));
108108

109109
let potentially_illegal_move =
110-
check_and_get_illegal_move_origin(bccx, move_info.cmt);
110+
check_and_get_illegal_move_origin(bccx, &move_info.cmt);
111111
match potentially_illegal_move {
112112
Some(illegal_move_origin) => {
113113
let error = MoveError::with_move_info(illegal_move_origin,
@@ -118,7 +118,7 @@ fn gather_move(bccx: &BorrowckCtxt,
118118
None => ()
119119
}
120120

121-
match opt_loan_path(move_info.cmt) {
121+
match opt_loan_path(&move_info.cmt) {
122122
Some(loan_path) => {
123123
move_data.add_move(bccx.tcx, loan_path,
124124
move_info.id, move_info.kind);
@@ -158,14 +158,14 @@ pub fn gather_move_and_assignment(bccx: &BorrowckCtxt,
158158
}
159159

160160
fn check_and_get_illegal_move_origin(bccx: &BorrowckCtxt,
161-
cmt: mc::cmt) -> Option<mc::cmt> {
161+
cmt: &mc::cmt) -> Option<mc::cmt> {
162162
match cmt.cat {
163163
mc::cat_deref(_, _, mc::BorrowedPtr(..)) |
164164
mc::cat_deref(_, _, mc::GcPtr) |
165165
mc::cat_deref(_, _, mc::UnsafePtr(..)) |
166166
mc::cat_upvar(..) | mc::cat_static_item |
167167
mc::cat_copied_upvar(mc::CopiedUpvar { onceness: ast::Many, .. }) => {
168-
Some(cmt)
168+
Some(cmt.clone())
169169
}
170170

171171
// Can move out of captured upvars only if the destination closure
@@ -181,12 +181,12 @@ fn check_and_get_illegal_move_origin(bccx: &BorrowckCtxt,
181181
None
182182
}
183183

184-
mc::cat_downcast(b) |
185-
mc::cat_interior(b, _) => {
184+
mc::cat_downcast(ref b) |
185+
mc::cat_interior(ref b, _) => {
186186
match ty::get(b.ty).sty {
187187
ty::ty_struct(did, _) | ty::ty_enum(did, _) => {
188188
if ty::has_dtor(bccx.tcx, did) {
189-
Some(cmt)
189+
Some(cmt.clone())
190190
} else {
191191
check_and_get_illegal_move_origin(bccx, b)
192192
}
@@ -197,8 +197,8 @@ fn check_and_get_illegal_move_origin(bccx: &BorrowckCtxt,
197197
}
198198
}
199199

200-
mc::cat_deref(b, _, mc::OwnedPtr) |
201-
mc::cat_discr(b, _) => {
200+
mc::cat_deref(ref b, _, mc::OwnedPtr) |
201+
mc::cat_discr(ref b, _) => {
202202
check_and_get_illegal_move_origin(bccx, b)
203203
}
204204
}

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

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ pub fn guarantee_lifetime(bccx: &BorrowckCtxt,
3939
cause: cause,
4040
loan_region: loan_region,
4141
loan_kind: loan_kind,
42-
cmt_original: cmt,
42+
cmt_original: cmt.clone(),
4343
root_scope_id: root_scope_id};
44-
ctxt.check(cmt, None)
44+
ctxt.check(&cmt, None)
4545
}
4646

4747
///////////////////////////////////////////////////////////////////////////
@@ -69,7 +69,7 @@ impl<'a> GuaranteeLifetimeContext<'a> {
6969
self.bccx.tcx
7070
}
7171

72-
fn check(&self, cmt: mc::cmt, discr_scope: Option<ast::NodeId>) -> R {
72+
fn check(&self, cmt: &mc::cmt, discr_scope: Option<ast::NodeId>) -> R {
7373
//! Main routine. Walks down `cmt` until we find the "guarantor".
7474
debug!("guarantee_lifetime.check(cmt={}, loan_region={})",
7575
cmt.repr(self.bccx.tcx),
@@ -83,15 +83,14 @@ impl<'a> GuaranteeLifetimeContext<'a> {
8383
mc::cat_upvar(..) |
8484
mc::cat_deref(_, _, mc::BorrowedPtr(..)) | // L-Deref-Borrowed
8585
mc::cat_deref(_, _, mc::UnsafePtr(..)) => {
86-
let scope = self.scope(cmt);
87-
self.check_scope(scope)
86+
self.check_scope(self.scope(cmt))
8887
}
8988

9089
mc::cat_static_item => {
9190
Ok(())
9291
}
9392

94-
mc::cat_deref(base, derefs, mc::GcPtr) => {
93+
mc::cat_deref(ref base, derefs, mc::GcPtr) => {
9594
let base_scope = self.scope(base);
9695

9796
// L-Deref-Managed-Imm-User-Root
@@ -111,13 +110,13 @@ impl<'a> GuaranteeLifetimeContext<'a> {
111110
}
112111
}
113112

114-
mc::cat_downcast(base) |
115-
mc::cat_deref(base, _, mc::OwnedPtr) | // L-Deref-Send
116-
mc::cat_interior(base, _) => { // L-Field
113+
mc::cat_downcast(ref base) |
114+
mc::cat_deref(ref base, _, mc::OwnedPtr) | // L-Deref-Send
115+
mc::cat_interior(ref base, _) => { // L-Field
117116
self.check(base, discr_scope)
118117
}
119118

120-
mc::cat_discr(base, new_discr_scope) => {
119+
mc::cat_discr(ref base, new_discr_scope) => {
121120
// Subtle: in a match, we must ensure that each binding
122121
// variable remains valid for the duration of the arm in
123122
// which it appears, presuming that this arm is taken.
@@ -176,7 +175,7 @@ impl<'a> GuaranteeLifetimeContext<'a> {
176175
}
177176

178177
fn is_rvalue_or_immutable(&self,
179-
cmt: mc::cmt) -> bool {
178+
cmt: &mc::cmt) -> bool {
180179
//! We can omit the root on an `@T` value if the location
181180
//! that holds the box is either (1) an rvalue, in which case
182181
//! it is in a non-user-accessible temporary, or (2) an immutable
@@ -189,8 +188,8 @@ impl<'a> GuaranteeLifetimeContext<'a> {
189188
}
190189

191190
fn check_root(&self,
192-
cmt_deref: mc::cmt,
193-
cmt_base: mc::cmt,
191+
cmt_deref: &mc::cmt,
192+
cmt_base: &mc::cmt,
194193
derefs: uint,
195194
discr_scope: Option<ast::NodeId>) -> R {
196195
debug!("check_root(cmt_deref={}, cmt_base={}, derefs={:?}, \
@@ -253,7 +252,7 @@ impl<'a> GuaranteeLifetimeContext<'a> {
253252
}
254253
}
255254

256-
fn is_moved(&self, cmt: mc::cmt) -> bool {
255+
fn is_moved(&self, cmt: &mc::cmt) -> bool {
257256
//! True if `cmt` is something that is potentially moved
258257
//! out of the current stack frame.
259258
@@ -269,17 +268,17 @@ impl<'a> GuaranteeLifetimeContext<'a> {
269268
mc::cat_upvar(..) => {
270269
false
271270
}
272-
r @ mc::cat_downcast(..) |
273-
r @ mc::cat_interior(..) |
274-
r @ mc::cat_discr(..) => {
271+
ref r @ mc::cat_downcast(..) |
272+
ref r @ mc::cat_interior(..) |
273+
ref r @ mc::cat_discr(..) => {
275274
self.tcx().sess.span_bug(
276275
cmt.span,
277276
format!("illegal guarantor category: {:?}", r));
278277
}
279278
}
280279
}
281280

282-
fn scope(&self, cmt: mc::cmt) -> ty::Region {
281+
fn scope(&self, cmt: &mc::cmt) -> ty::Region {
283282
//! Returns the maximal region scope for the which the
284283
//! lvalue `cmt` is guaranteed to be valid without any
285284
//! rooting etc, and presuming `cmt` is not mutated.
@@ -307,18 +306,18 @@ impl<'a> GuaranteeLifetimeContext<'a> {
307306
mc::cat_deref(_, _, mc::BorrowedPtr(_, r)) => {
308307
r
309308
}
310-
mc::cat_downcast(cmt) |
311-
mc::cat_deref(cmt, _, mc::OwnedPtr) |
312-
mc::cat_deref(cmt, _, mc::GcPtr) |
313-
mc::cat_interior(cmt, _) |
314-
mc::cat_discr(cmt, _) => {
309+
mc::cat_downcast(ref cmt) |
310+
mc::cat_deref(ref cmt, _, mc::OwnedPtr) |
311+
mc::cat_deref(ref cmt, _, mc::GcPtr) |
312+
mc::cat_interior(ref cmt, _) |
313+
mc::cat_discr(ref cmt, _) => {
315314
self.scope(cmt)
316315
}
317316
}
318317
}
319318

320319
fn report_error(&self, code: bckerr_code) {
321-
self.bccx.report(BckError { cmt: self.cmt_original,
320+
self.bccx.report(BckError { cmt: self.cmt_original.clone(),
322321
span: self.span,
323322
cause: self.cause,
324323
code: code });

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
230230
let cmt = this.bccx.cat_expr(ex_v);
231231
for arm in arms.iter() {
232232
for pat in arm.pats.iter() {
233-
this.gather_pat(cmt, *pat, Some((arm.body.id, ex.id)));
233+
this.gather_pat(cmt.clone(), *pat, Some((arm.body.id, ex.id)));
234234
}
235235
}
236236
visit::walk_expr(this, ex, ());
@@ -300,7 +300,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
300300

301301
fn with_assignee_loan_path(bccx: &BorrowckCtxt, expr: &ast::Expr, op: |Rc<LoanPath>|) {
302302
let cmt = bccx.cat_expr(expr);
303-
match opt_loan_path(cmt) {
303+
match opt_loan_path(&cmt) {
304304
Some(lp) => op(lp),
305305
None => {
306306
// This can occur with e.g. `*foo() = 5`. In such
@@ -552,28 +552,28 @@ impl<'a> GatherLoanCtxt<'a> {
552552
// Check that the lifetime of the borrow does not exceed
553553
// the lifetime of the data being borrowed.
554554
if lifetime::guarantee_lifetime(self.bccx, self.item_ub, root_ub,
555-
borrow_span, cause, cmt, loan_region,
555+
borrow_span, cause, cmt.clone(), loan_region,
556556
req_kind).is_err() {
557557
return; // reported an error, no sense in reporting more.
558558
}
559559

560560
// Check that we don't allow mutable borrows of non-mutable data.
561561
if check_mutability(self.bccx, borrow_span, cause,
562-
cmt, req_kind).is_err() {
562+
cmt.clone(), req_kind).is_err() {
563563
return; // reported an error, no sense in reporting more.
564564
}
565565

566566
// Check that we don't allow mutable borrows of aliasable data.
567567
if check_aliasability(self.bccx, borrow_span, cause,
568-
cmt, req_kind).is_err() {
568+
cmt.clone(), req_kind).is_err() {
569569
return; // reported an error, no sense in reporting more.
570570
}
571571

572572
// Compute the restrictions that are required to enforce the
573573
// loan is safe.
574574
let restr = restrictions::compute_restrictions(
575575
self.bccx, borrow_span, cause,
576-
cmt, loan_region, self.restriction_set(req_kind));
576+
cmt.clone(), loan_region, self.restriction_set(req_kind));
577577

578578
// Create the loan record (if needed).
579579
let loan = match restr {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub struct GroupedMoveErrors {
7979
fn report_move_errors(bccx: &BorrowckCtxt, errors: &Vec<MoveError>) {
8080
let grouped_errors = group_errors_with_same_origin(errors);
8181
for error in grouped_errors.iter() {
82-
report_cannot_move_out_of(bccx, error.move_from);
82+
report_cannot_move_out_of(bccx, error.move_from.clone());
8383
let mut is_first_note = true;
8484
for move_to in error.move_to_places.iter() {
8585
note_move_destination(bccx, move_to.span,
@@ -112,7 +112,7 @@ fn group_errors_with_same_origin(errors: &Vec<MoveError>)
112112
}
113113
}
114114
grouped_errors.push(GroupedMoveErrors {
115-
move_from: error.move_from,
115+
move_from: error.move_from.clone(),
116116
move_to_places: move_to
117117
})
118118
}
@@ -128,11 +128,11 @@ fn report_cannot_move_out_of(bccx: &BorrowckCtxt, move_from: mc::cmt) {
128128
bccx.span_err(
129129
move_from.span,
130130
format!("cannot move out of {}",
131-
bccx.cmt_to_str(move_from)));
131+
bccx.cmt_to_str(&*move_from)));
132132
}
133133

134-
mc::cat_downcast(b) |
135-
mc::cat_interior(b, _) => {
134+
mc::cat_downcast(ref b) |
135+
mc::cat_interior(ref b, _) => {
136136
match ty::get(b.ty).sty {
137137
ty::ty_struct(did, _)
138138
| ty::ty_enum(did, _) if ty::has_dtor(bccx.tcx, did) => {

0 commit comments

Comments
 (0)