]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/borrowck/check_loans.rs
Replace all ~"" with "".to_owned()
[rust.git] / src / librustc / middle / borrowck / check_loans.rs
index 590229a6652a29a6a8ca29a38e928783ea724d56..5e0425141ac82e64f5e806f1df7150aaefe26d71 100644 (file)
@@ -22,6 +22,7 @@
 use middle::borrowck::*;
 use middle::moves;
 use middle::ty;
+use middle::typeck::MethodCall;
 use syntax::ast;
 use syntax::ast_util;
 use syntax::codemap::Span;
@@ -30,9 +31,9 @@
 use util::ppaux::Repr;
 
 struct CheckLoanCtxt<'a> {
-    bccx: &'a BorrowckCtxt,
-    dfcx_loans: &'a LoanDataFlow,
-    move_data: move_data::FlowedMoveData,
+    bccx: &'a BorrowckCtxt<'a>,
+    dfcx_loans: &'a LoanDataFlow<'a>,
+    move_data: move_data::FlowedMoveData<'a>,
     all_loans: &'a [Loan],
 }
 
@@ -85,7 +86,7 @@ enum MoveError {
 }
 
 impl<'a> CheckLoanCtxt<'a> {
-    pub fn tcx(&self) -> ty::ctxt { self.bccx.tcx }
+    pub fn tcx(&self) -> &'a ty::ctxt { self.bccx.tcx }
 
     pub fn each_issued_loan(&self, scope_id: ast::NodeId, op: |&Loan| -> bool)
                             -> bool {
@@ -143,11 +144,11 @@ pub fn each_in_scope_restriction(&self,
         })
     }
 
-    pub fn loans_generated_by(&self, scope_id: ast::NodeId) -> ~[uint] {
+    pub fn loans_generated_by(&self, scope_id: ast::NodeId) -> Vec<uint> {
         //! Returns a vector of the loans that are generated as
         //! we encounter `scope_id`.
 
-        let mut result = ~[];
+        let mut result = Vec::new();
         self.dfcx_loans.each_gen_bit_frozen(scope_id, |loan_index| {
             result.push(loan_index);
             true
@@ -239,7 +240,7 @@ pub fn report_error_if_loan_conflicts_with_restriction(&self,
             if restr.loan_path != loan2.loan_path { continue; }
 
             let old_pronoun = if new_loan.loan_path == old_loan.loan_path {
-                ~"it"
+                "it".to_owned()
             } else {
                 format!("`{}`",
                         self.bccx.loan_path_to_str(old_loan.loan_path))
@@ -377,11 +378,7 @@ pub fn check_if_path_is_moved(&self,
     pub fn check_assignment(&self, expr: &ast::Expr) {
         // We don't use cat_expr() here because we don't want to treat
         // auto-ref'd parameters in overloaded operators as rvalues.
-        let adj = {
-            let adjustments = self.bccx.tcx.adjustments.borrow();
-            adjustments.get().find_copy(&expr.id)
-        };
-        let cmt = match adj {
+        let cmt = match self.bccx.tcx.adjustments.borrow().find_copy(&expr.id) {
             None => self.bccx.cat_expr_unadjusted(expr),
             Some(adj) => self.bccx.cat_expr_autoderefd(expr, adj)
         };
@@ -451,10 +448,7 @@ fn mark_variable_as_used_mut(this: &CheckLoanCtxt,
                        cmt.repr(this.tcx()));
                 match cmt.cat {
                     mc::cat_local(id) | mc::cat_arg(id) => {
-                        let mut used_mut_nodes = this.tcx()
-                                                     .used_mut_nodes
-                                                     .borrow_mut();
-                        used_mut_nodes.get().insert(id);
+                        this.tcx().used_mut_nodes.borrow_mut().insert(id);
                         return;
                     }
 
@@ -516,10 +510,13 @@ fn check_for_aliasability_violation(this: &CheckLoanCtxt,
                                             expr: &ast::Expr,
                                             cmt: mc::cmt)
                                             -> bool {
-            match cmt.freely_aliasable() {
+            match cmt.freely_aliasable(this.tcx()) {
                 None => {
                     return true;
                 }
+                Some(mc::AliasableStaticMut(..)) => {
+                    return true;
+                }
                 Some(cause) => {
                     this.bccx.report_aliasability_violation(
                         expr.span,
@@ -713,9 +710,7 @@ fn check_move_out_from_id(&self, id: ast::NodeId, span: Span) {
     fn check_captured_variables(&self,
                                 closure_id: ast::NodeId,
                                 span: Span) {
-        let capture_map = self.bccx.capture_map.borrow();
-        let cap_vars = capture_map.get().get(&closure_id);
-        for cap_var in cap_vars.borrow().iter() {
+        for cap_var in self.bccx.capture_map.get(&closure_id).iter() {
             let var_id = ast_util::def_id_of_def(cap_var.def).node;
             let var_path = @LpVar(var_id);
             self.check_if_path_is_moved(closure_id, span,
@@ -784,7 +779,6 @@ pub fn analyze_move_out_from(&self,
     pub fn check_call(&self,
                       _expr: &ast::Expr,
                       _callee: Option<@ast::Expr>,
-                      _callee_id: ast::NodeId,
                       _callee_span: Span,
                       _args: &[@ast::Expr]) {
         // NB: This call to check for conflicting loans is not truly
@@ -828,23 +822,22 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,
           this.check_captured_variables(expr.id, expr.span)
       }
       ast::ExprAssign(dest, _) |
-      ast::ExprAssignOp(_, _, dest, _) => {
+      ast::ExprAssignOp(_, dest, _) => {
         this.check_assignment(dest);
       }
       ast::ExprCall(f, ref args) => {
-        this.check_call(expr, Some(f), f.id, f.span, *args);
+        this.check_call(expr, Some(f), f.span, args.as_slice());
       }
-      ast::ExprMethodCall(callee_id, _, _, ref args) => {
-        this.check_call(expr, None, callee_id, expr.span, *args);
+      ast::ExprMethodCall(_, _, ref args) => {
+        this.check_call(expr, None, expr.span, args.as_slice());
       }
-      ast::ExprIndex(callee_id, _, rval) |
-      ast::ExprBinary(callee_id, _, _, rval)
-      if method_map.get().contains_key(&expr.id) => {
-        this.check_call(expr, None, callee_id, expr.span, [rval]);
+      ast::ExprIndex(_, rval) | ast::ExprBinary(_, _, rval)
+      if method_map.contains_key(&MethodCall::expr(expr.id)) => {
+        this.check_call(expr, None, expr.span, [rval]);
       }
-      ast::ExprUnary(callee_id, _, _) | ast::ExprIndex(callee_id, _, _)
-      if method_map.get().contains_key(&expr.id) => {
-        this.check_call(expr, None, callee_id, expr.span, []);
+      ast::ExprUnary(_, _) | ast::ExprIndex(_, _)
+      if method_map.contains_key(&MethodCall::expr(expr.id)) => {
+        this.check_call(expr, None, expr.span, []);
       }
       ast::ExprInlineAsm(ref ia) => {
           for &(_, out) in ia.outputs.iter() {