1 // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // ----------------------------------------------------------------------
14 // Phase 2 of check: we walk down the tree and check that:
15 // 1. assignments are always made to mutable locations;
16 // 2. loans made in overlapping scopes do not conflict
17 // 3. assignments do not affect things loaned out as immutable
18 // 4. moves do not affect things loaned out in any way
21 use middle::borrowck::*;
22 use middle::expr_use_visitor as euv;
23 use middle::mem_categorization as mc;
26 use syntax::codemap::Span;
27 use util::ppaux::Repr;
31 // FIXME (#16118): These functions are intended to allow the borrow checker to
32 // be less precise in its handling of Box while still allowing moves out of a
33 // Box. They should be removed when OwnedPtr is removed from LoanPath.
35 fn owned_ptr_base_path<'a>(loan_path: &'a LoanPath) -> &'a LoanPath {
36 //! Returns the base of the leftmost dereference of an OwnedPtr in
37 //! `loan_path`. If there is no dereference of an OwnedPtr in `loan_path`,
38 //! then it just returns `loan_path` itself.
40 return match owned_ptr_base_path_helper(loan_path) {
41 Some(new_loan_path) => new_loan_path,
42 None => loan_path.clone()
45 fn owned_ptr_base_path_helper<'a>(loan_path: &'a LoanPath) -> Option<&'a LoanPath> {
47 LpVar(_) | LpUpvar(_) => None,
48 LpExtend(ref lp_base, _, LpDeref(mc::OwnedPtr)) => {
49 match owned_ptr_base_path_helper(&**lp_base) {
51 None => Some(&**lp_base)
54 LpExtend(ref lp_base, _, _) => owned_ptr_base_path_helper(&**lp_base)
59 fn owned_ptr_base_path_rc(loan_path: &Rc<LoanPath>) -> Rc<LoanPath> {
60 //! The equivalent of `owned_ptr_base_path` for an &Rc<LoanPath> rather than
63 return match owned_ptr_base_path_helper(loan_path) {
64 Some(new_loan_path) => new_loan_path,
65 None => loan_path.clone()
68 fn owned_ptr_base_path_helper(loan_path: &Rc<LoanPath>) -> Option<Rc<LoanPath>> {
70 LpVar(_) | LpUpvar(_) => None,
71 LpExtend(ref lp_base, _, LpDeref(mc::OwnedPtr)) => {
72 match owned_ptr_base_path_helper(lp_base) {
74 None => Some(lp_base.clone())
77 LpExtend(ref lp_base, _, _) => owned_ptr_base_path_helper(lp_base)
82 struct CheckLoanCtxt<'a, 'tcx: 'a> {
83 bccx: &'a BorrowckCtxt<'a, 'tcx>,
84 dfcx_loans: &'a LoanDataFlow<'a, 'tcx>,
85 move_data: move_data::FlowedMoveData<'a, 'tcx>,
86 all_loans: &'a [Loan],
89 impl<'a, 'tcx> euv::Delegate for CheckLoanCtxt<'a, 'tcx> {
91 consume_id: ast::NodeId,
94 mode: euv::ConsumeMode) {
95 debug!("consume(consume_id={}, cmt={}, mode={})",
96 consume_id, cmt.repr(self.tcx()), mode);
98 self.consume_common(consume_id, consume_span, cmt, mode);
101 fn consume_pat(&mut self,
102 consume_pat: &ast::Pat,
104 mode: euv::ConsumeMode) {
105 debug!("consume_pat(consume_pat={}, cmt={}, mode={})",
106 consume_pat.repr(self.tcx()),
107 cmt.repr(self.tcx()),
110 self.consume_common(consume_pat.id, consume_pat.span, cmt, mode);
114 borrow_id: ast::NodeId,
117 loan_region: ty::Region,
119 loan_cause: euv::LoanCause)
121 debug!("borrow(borrow_id={}, cmt={}, loan_region={}, \
122 bk={}, loan_cause={})",
123 borrow_id, cmt.repr(self.tcx()), loan_region,
126 match opt_loan_path(&cmt) {
128 let moved_value_use_kind = match loan_cause {
129 euv::ClosureCapture(_) => MovedInCapture,
132 self.check_if_path_is_moved(borrow_id, borrow_span, moved_value_use_kind, &lp);
137 self.check_for_conflicting_loans(borrow_id);
141 assignment_id: ast::NodeId,
142 assignment_span: Span,
143 assignee_cmt: mc::cmt,
144 mode: euv::MutateMode)
146 debug!("mutate(assignment_id={}, assignee_cmt={})",
147 assignment_id, assignee_cmt.repr(self.tcx()));
149 match opt_loan_path(&assignee_cmt) {
152 euv::Init | euv::JustWrite => {
153 // In a case like `path = 1`, then path does not
154 // have to be *FULLY* initialized, but we still
155 // must be careful lest it contains derefs of
157 self.check_if_assigned_path_is_moved(assignee_cmt.id,
162 euv::WriteAndRead => {
163 // In a case like `path += 1`, then path must be
164 // fully initialized, since we will read it before
166 self.check_if_path_is_moved(assignee_cmt.id,
176 self.check_assignment(assignment_id, assignment_span, assignee_cmt, mode);
179 fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) { }
182 pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
183 dfcx_loans: &LoanDataFlow<'b, 'tcx>,
184 move_data: move_data::FlowedMoveData<'c, 'tcx>,
188 debug!("check_loans(body id={})", body.id);
190 let mut clcx = CheckLoanCtxt {
192 dfcx_loans: dfcx_loans,
193 move_data: move_data,
194 all_loans: all_loans,
198 let mut euv = euv::ExprUseVisitor::new(&mut clcx, bccx.tcx);
199 euv.walk_fn(decl, body);
203 #[deriving(PartialEq)]
206 UseWhileBorrowed(/*loan*/Rc<LoanPath>, /*loan*/Span)
209 fn compatible_borrow_kinds(borrow_kind1: ty::BorrowKind,
210 borrow_kind2: ty::BorrowKind)
212 borrow_kind1 == ty::ImmBorrow && borrow_kind2 == ty::ImmBorrow
215 impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
216 pub fn tcx(&self) -> &'a ty::ctxt<'tcx> { self.bccx.tcx }
218 pub fn each_issued_loan(&self, scope_id: ast::NodeId, op: |&Loan| -> bool)
220 //! Iterates over each loan that has been issued
221 //! on entrance to `scope_id`, regardless of whether it is
222 //! actually *in scope* at that point. Sometimes loans
223 //! are issued for future scopes and thus they may have been
224 //! *issued* but not yet be in effect.
226 self.dfcx_loans.each_bit_on_entry(scope_id, |loan_index| {
227 let loan = &self.all_loans[loan_index];
232 pub fn each_in_scope_loan(&self,
233 scope_id: ast::NodeId,
236 //! Like `each_issued_loan()`, but only considers loans that are
237 //! currently in scope.
239 let tcx = self.tcx();
240 self.each_issued_loan(scope_id, |loan| {
241 if tcx.region_maps.is_subscope_of(scope_id, loan.kill_scope) {
249 fn each_in_scope_loan_affecting_path(&self,
250 scope_id: ast::NodeId,
251 loan_path: &LoanPath,
254 //! Iterates through all of the in-scope loans affecting `loan_path`,
255 //! calling `op`, and ceasing iteration if `false` is returned.
257 // First, we check for a loan restricting the path P being used. This
258 // accounts for borrows of P but also borrows of subpaths, like P.a.b.
259 // Consider the following example:
261 // let x = &mut a.b.c; // Restricts a, a.b, and a.b.c
262 // let y = a; // Conflicts with restriction
264 let loan_path = owned_ptr_base_path(loan_path);
265 let cont = self.each_in_scope_loan(scope_id, |loan| {
267 for restr_path in loan.restricted_paths.iter() {
268 if **restr_path == *loan_path {
282 // Next, we must check for *loans* (not restrictions) on the path P or
283 // any base path. This rejects examples like the following:
288 // Limiting this search to *loans* and not *restrictions* means that
289 // examples like the following continue to work:
294 let mut loan_path = loan_path;
297 LpVar(_) | LpUpvar(_) => {
300 LpExtend(ref lp_base, _, _) => {
301 loan_path = &**lp_base;
305 let cont = self.each_in_scope_loan(scope_id, |loan| {
306 if *loan.loan_path == *loan_path {
321 pub fn loans_generated_by(&self, scope_id: ast::NodeId) -> Vec<uint> {
322 //! Returns a vector of the loans that are generated as
323 //! we encounter `scope_id`.
325 let mut result = Vec::new();
326 self.dfcx_loans.each_gen_bit(scope_id, |loan_index| {
327 result.push(loan_index);
333 pub fn check_for_conflicting_loans(&self, scope_id: ast::NodeId) {
334 //! Checks to see whether any of the loans that are issued
335 //! by `scope_id` conflict with loans that have already been
336 //! issued when we enter `scope_id` (for example, we do not
337 //! permit two `&mut` borrows of the same variable).
339 debug!("check_for_conflicting_loans(scope_id={})", scope_id);
341 let new_loan_indices = self.loans_generated_by(scope_id);
342 debug!("new_loan_indices = {}", new_loan_indices);
344 self.each_issued_loan(scope_id, |issued_loan| {
345 for &new_loan_index in new_loan_indices.iter() {
346 let new_loan = &self.all_loans[new_loan_index];
347 self.report_error_if_loans_conflict(issued_loan, new_loan);
352 for (i, &x) in new_loan_indices.iter().enumerate() {
353 let old_loan = &self.all_loans[x];
354 for &y in new_loan_indices.slice_from(i+1).iter() {
355 let new_loan = &self.all_loans[y];
356 self.report_error_if_loans_conflict(old_loan, new_loan);
361 pub fn report_error_if_loans_conflict(&self,
364 //! Checks whether `old_loan` and `new_loan` can safely be issued
367 debug!("report_error_if_loans_conflict(old_loan={}, new_loan={})",
368 old_loan.repr(self.tcx()),
369 new_loan.repr(self.tcx()));
371 // Should only be called for loans that are in scope at the same time.
372 assert!(self.tcx().region_maps.scopes_intersect(old_loan.kill_scope,
373 new_loan.kill_scope));
375 self.report_error_if_loan_conflicts_with_restriction(
376 old_loan, new_loan, old_loan, new_loan) &&
377 self.report_error_if_loan_conflicts_with_restriction(
378 new_loan, old_loan, old_loan, new_loan);
381 pub fn report_error_if_loan_conflicts_with_restriction(&self,
387 //! Checks whether the restrictions introduced by `loan1` would
388 //! prohibit `loan2`. Returns false if an error is reported.
390 debug!("report_error_if_loan_conflicts_with_restriction(\
391 loan1={}, loan2={})",
392 loan1.repr(self.tcx()),
393 loan2.repr(self.tcx()));
395 if compatible_borrow_kinds(loan1.kind, loan2.kind) {
399 let loan2_base_path = owned_ptr_base_path_rc(&loan2.loan_path);
400 for restr_path in loan1.restricted_paths.iter() {
401 if *restr_path != loan2_base_path { continue; }
403 // If new_loan is something like `x.a`, and old_loan is something like `x.b`, we would
404 // normally generate a rather confusing message (in this case, for multiple mutable
407 // error: cannot borrow `x.b` as mutable more than once at a time
408 // note: previous borrow of `x.a` occurs here; the mutable borrow prevents
409 // subsequent moves, borrows, or modification of `x.a` until the borrow ends
411 // What we want to do instead is get the 'common ancestor' of the two borrow paths and
412 // use that for most of the message instead, giving is something like this:
414 // error: cannot borrow `x` as mutable more than once at a time
415 // note: previous borrow of `x` occurs here (through borrowing `x.a`); the mutable
416 // borrow prevents subsequent moves, borrows, or modification of `x` until the
419 let common = new_loan.loan_path.common(&*old_loan.loan_path);
420 let (nl, ol, new_loan_msg, old_loan_msg) =
421 if new_loan.loan_path.has_fork(&*old_loan.loan_path) && common.is_some() {
422 let nl = self.bccx.loan_path_to_string(&common.unwrap());
424 let new_loan_msg = format!(" (here through borrowing `{}`)",
425 self.bccx.loan_path_to_string(
426 &*new_loan.loan_path));
427 let old_loan_msg = format!(" (through borrowing `{}`)",
428 self.bccx.loan_path_to_string(
429 &*old_loan.loan_path));
430 (nl, ol, new_loan_msg, old_loan_msg)
432 (self.bccx.loan_path_to_string(&*new_loan.loan_path),
433 self.bccx.loan_path_to_string(&*old_loan.loan_path),
434 String::new(), String::new())
437 let ol_pronoun = if new_loan.loan_path == old_loan.loan_path {
443 match (new_loan.kind, old_loan.kind) {
444 (ty::MutBorrow, ty::MutBorrow) => {
447 format!("cannot borrow `{}`{} as mutable \
448 more than once at a time",
449 nl, new_loan_msg).as_slice())
452 (ty::UniqueImmBorrow, _) => {
455 format!("closure requires unique access to `{}` \
456 but {} is already borrowed{}",
457 nl, ol_pronoun, old_loan_msg).as_slice());
460 (_, ty::UniqueImmBorrow) => {
463 format!("cannot borrow `{}`{} as {} because \
464 previous closure requires unique access",
465 nl, new_loan_msg, new_loan.kind.to_user_str()).as_slice());
471 format!("cannot borrow `{}`{} as {} because \
472 {} is also borrowed as {}{}",
475 new_loan.kind.to_user_str(),
477 old_loan.kind.to_user_str(),
478 old_loan_msg).as_slice());
482 match new_loan.cause {
483 euv::ClosureCapture(span) => {
486 format!("borrow occurs due to use of `{}` in closure",
492 let rule_summary = match old_loan.kind {
494 format!("the mutable borrow prevents subsequent \
495 moves, borrows, or modification of `{0}` \
496 until the borrow ends",
501 format!("the immutable borrow prevents subsequent \
502 moves or mutable borrows of `{0}` \
503 until the borrow ends",
507 ty::UniqueImmBorrow => {
508 format!("the unique capture prevents subsequent \
509 moves or borrows of `{0}` \
510 until the borrow ends",
515 let borrow_summary = match old_loan.cause {
516 euv::ClosureCapture(_) => {
517 format!("previous borrow of `{}` occurs here{} due to \
522 euv::OverloadedOperator(..) |
525 euv::ClosureInvocation(..) |
527 euv::RefBinding(..) |
528 euv::MatchDiscriminant(..) => {
529 format!("previous borrow of `{}` occurs here{}",
536 format!("{}; {}", borrow_summary, rule_summary).as_slice());
538 let old_loan_span = self.tcx().map.span(old_loan.kill_scope);
539 self.bccx.span_end_note(old_loan_span,
540 "previous borrow ends here");
548 fn is_local_variable_or_arg(&self, cmt: mc::cmt) -> bool {
550 mc::cat_local(_) => true,
555 fn consume_common(&self,
559 mode: euv::ConsumeMode) {
560 match opt_loan_path(&cmt) {
562 let moved_value_use_kind = match mode {
564 self.check_for_copy_of_frozen_path(id, span, &*lp);
568 match self.move_data.kind_of_move_of_path(id, &lp) {
570 // Sometimes moves don't have a move kind;
571 // this either means that the original move
572 // was from something illegal to move,
573 // or was moved from referent of an unsafe
574 // pointer or something like that.
578 self.check_for_move_of_borrowed_path(id, span,
580 if move_kind == move_data::Captured {
590 self.check_if_path_is_moved(id, span, moved_value_use_kind, &lp);
596 fn check_for_copy_of_frozen_path(&self,
599 copy_path: &LoanPath) {
600 match self.analyze_restrictions_on_use(id, copy_path, ty::ImmBorrow) {
602 UseWhileBorrowed(loan_path, loan_span) => {
605 format!("cannot use `{}` because it was mutably borrowed",
606 self.bccx.loan_path_to_string(copy_path).as_slice())
610 format!("borrow of `{}` occurs here",
611 self.bccx.loan_path_to_string(&*loan_path).as_slice())
617 fn check_for_move_of_borrowed_path(&self,
620 move_path: &LoanPath,
621 move_kind: move_data::MoveKind) {
622 // We want to detect if there are any loans at all, so we search for
623 // any loans incompatible with MutBorrrow, since all other kinds of
624 // loans are incompatible with that.
625 match self.analyze_restrictions_on_use(id, move_path, ty::MutBorrow) {
627 UseWhileBorrowed(loan_path, loan_span) => {
628 let err_message = match move_kind {
629 move_data::Captured =>
630 format!("cannot move `{}` into closure because it is borrowed",
631 self.bccx.loan_path_to_string(move_path).as_slice()),
632 move_data::Declared |
633 move_data::MoveExpr |
634 move_data::MovePat =>
635 format!("cannot move out of `{}` because it is borrowed",
636 self.bccx.loan_path_to_string(move_path).as_slice())
639 self.bccx.span_err(span, err_message.as_slice());
642 format!("borrow of `{}` occurs here",
643 self.bccx.loan_path_to_string(&*loan_path).as_slice())
649 pub fn analyze_restrictions_on_use(&self,
650 expr_id: ast::NodeId,
652 borrow_kind: ty::BorrowKind)
654 debug!("analyze_restrictions_on_use(expr_id={}, use_path={})",
655 self.tcx().map.node_to_string(expr_id),
656 use_path.repr(self.tcx()));
660 self.each_in_scope_loan_affecting_path(expr_id, use_path, |loan| {
661 if !compatible_borrow_kinds(loan.kind, borrow_kind) {
662 ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span);
672 fn check_if_path_is_moved(&self,
675 use_kind: MovedValueUseKind,
678 * Reports an error if `expr` (which should be a path)
679 * is using a moved/uninitialized value
682 debug!("check_if_path_is_moved(id={}, use_kind={}, lp={})",
683 id, use_kind, lp.repr(self.bccx.tcx));
684 let base_lp = owned_ptr_base_path_rc(lp);
685 self.move_data.each_move_of(id, &base_lp, |the_move, moved_lp| {
686 self.bccx.report_use_of_moved_value(
696 fn check_if_assigned_path_is_moved(&self,
699 use_kind: MovedValueUseKind,
703 * Reports an error if assigning to `lp` will use a
704 * moved/uninitialized value. Mainly this is concerned with
705 * detecting derefs of uninitialized pointers.
710 * a = 10; // ok, even though a is uninitialized
712 * struct Point { x: uint, y: uint }
714 * p.x = 22; // ok, even though `p` is uninitialized
717 * (*p).x = 22; // not ok, p is uninitialized, can't deref
721 LpVar(_) | LpUpvar(_) => {
722 // assigning to `x` does not require that `x` is initialized
724 LpExtend(ref lp_base, _, LpInterior(_)) => {
725 // assigning to `P.f` is ok if assigning to `P` is ok
726 self.check_if_assigned_path_is_moved(id, span,
729 LpExtend(ref lp_base, _, LpDeref(_)) => {
730 // assigning to `(*P)` requires that `P` be initialized
731 self.check_if_path_is_moved(id, span,
737 fn check_assignment(&self,
738 assignment_id: ast::NodeId,
739 assignment_span: Span,
740 assignee_cmt: mc::cmt,
741 mode: euv::MutateMode) {
742 debug!("check_assignment(assignee_cmt={})", assignee_cmt.repr(self.tcx()));
744 // Mutable values can be assigned, as long as they obey loans
745 // and aliasing restrictions:
746 if assignee_cmt.mutbl.is_mutable() {
747 if check_for_aliasable_mutable_writes(self, assignment_span, assignee_cmt.clone()) {
748 if mode != euv::Init {
749 check_for_assignment_to_borrowed_path(
750 self, assignment_id, assignment_span, assignee_cmt.clone());
751 mark_variable_as_used_mut(self, assignee_cmt);
757 // Initializations are OK.
758 if mode == euv::Init {
762 // For immutable local variables, assignments are legal
763 // if they cannot already have been assigned
764 if self.is_local_variable_or_arg(assignee_cmt.clone()) {
765 assert!(assignee_cmt.mutbl.is_immutable()); // no "const" locals
766 let lp = opt_loan_path(&assignee_cmt).unwrap();
767 self.move_data.each_assignment_of(assignment_id, &lp, |assign| {
768 self.bccx.report_reassigned_immutable_variable(
777 // Otherwise, just a plain error.
778 match assignee_cmt.note {
779 mc::NoteClosureEnv(upvar_id) => {
780 // If this is an `Fn` closure, it simply can't mutate upvars.
781 // If it's an `FnMut` closure, the original variable was declared immutable.
782 // We need to determine which is the case here.
783 let kind = match assignee_cmt.upvar().unwrap().cat {
784 mc::cat_upvar(mc::Upvar { kind, .. }) => kind,
787 if kind == ty::FnUnboxedClosureKind {
790 format!("cannot assign to {}",
791 self.bccx.cmt_to_string(&*assignee_cmt)).as_slice());
793 self.tcx().map.span(upvar_id.closure_expr_id),
794 "consider changing this closure to take self by mutable reference");
798 format!("cannot assign to {} {}",
799 assignee_cmt.mutbl.to_user_str(),
800 self.bccx.cmt_to_string(&*assignee_cmt)).as_slice());
803 _ => match opt_loan_path(&assignee_cmt) {
807 format!("cannot assign to {} {} `{}`",
808 assignee_cmt.mutbl.to_user_str(),
809 self.bccx.cmt_to_string(&*assignee_cmt),
810 self.bccx.loan_path_to_string(&*lp)).as_slice());
815 format!("cannot assign to {} {}",
816 assignee_cmt.mutbl.to_user_str(),
817 self.bccx.cmt_to_string(&*assignee_cmt)).as_slice());
823 fn mark_variable_as_used_mut(this: &CheckLoanCtxt,
825 //! If the mutability of the `cmt` being written is inherited
826 //! from a local variable, liveness will
827 //! not have been able to detect that this variable's mutability
828 //! is important, so we must add the variable to the
829 //! `used_mut_nodes` table here.
832 debug!("mark_variable_as_used_mut(cmt={})", cmt.repr(this.tcx()));
833 match cmt.cat.clone() {
834 mc::cat_upvar(mc::Upvar { id: ty::UpvarId { var_id: id, .. }, .. }) |
835 mc::cat_local(id) => {
836 this.tcx().used_mut_nodes.borrow_mut().insert(id);
841 mc::cat_static_item |
842 mc::cat_deref(_, _, mc::UnsafePtr(..)) |
843 mc::cat_deref(_, _, mc::Implicit(..)) => {
844 assert_eq!(cmt.mutbl, mc::McDeclared);
848 mc::cat_deref(_, _, mc::BorrowedPtr(..)) => {
849 assert_eq!(cmt.mutbl, mc::McDeclared);
850 // We need to drill down to upvar if applicable
857 mc::cat_deref(b, _, mc::OwnedPtr) => {
858 assert_eq!(cmt.mutbl, mc::McInherited);
862 mc::cat_downcast(b) |
863 mc::cat_interior(b, _) => {
864 assert_eq!(cmt.mutbl, mc::McInherited);
871 fn check_for_aliasable_mutable_writes(this: &CheckLoanCtxt,
873 cmt: mc::cmt) -> bool {
874 //! Safety checks related to writes to aliasable, mutable locations
876 let guarantor = cmt.guarantor();
877 debug!("check_for_aliasable_mutable_writes(cmt={}, guarantor={})",
878 cmt.repr(this.tcx()), guarantor.repr(this.tcx()));
879 match guarantor.cat {
880 mc::cat_deref(ref b, _, mc::BorrowedPtr(ty::MutBorrow, _)) => {
881 // Statically prohibit writes to `&mut` when aliasable
883 check_for_aliasability_violation(this, span, b.clone());
889 return true; // no errors reported
892 fn check_for_aliasability_violation(this: &CheckLoanCtxt,
896 match cmt.freely_aliasable(this.tcx()) {
900 Some(mc::AliasableStaticMut(..)) => {
904 this.bccx.report_aliasability_violation(
913 fn check_for_assignment_to_borrowed_path(
914 this: &CheckLoanCtxt,
915 assignment_id: ast::NodeId,
916 assignment_span: Span,
917 assignee_cmt: mc::cmt)
919 //! Check for assignments that violate the terms of an
920 //! outstanding loan.
922 let loan_path = match opt_loan_path(&assignee_cmt) {
924 None => { return; /* no loan path, can't be any loans */ }
927 this.each_in_scope_loan_affecting_path(assignment_id, &*loan_path, |loan| {
928 this.report_illegal_mutation(assignment_span, &*loan_path, loan);
934 pub fn report_illegal_mutation(&self,
936 loan_path: &LoanPath,
940 format!("cannot assign to `{}` because it is borrowed",
941 self.bccx.loan_path_to_string(loan_path)).as_slice());
944 format!("borrow of `{}` occurs here",
945 self.bccx.loan_path_to_string(loan_path)).as_slice());