]> git.lizzy.rs Git - rust.git/commitdiff
Autoderef in librustc_borrowck
authorJonas Schievink <jonas@schievink.net>
Tue, 9 Feb 2016 20:42:39 +0000 (21:42 +0100)
committerJonas Schievink <jonas@schievink.net>
Fri, 12 Feb 2016 18:28:42 +0000 (19:28 +0100)
src/librustc_borrowck/borrowck/check_loans.rs
src/librustc_borrowck/borrowck/gather_loans/mod.rs
src/librustc_borrowck/borrowck/mod.rs
src/librustc_borrowck/borrowck/move_data.rs
src/librustc_borrowck/graphviz.rs

index 5e8495ceddd970c7fcf4e7363ddc202ec29e8645..f19a8658a057b5e1fb0332175f3bac1ccef90604 100644 (file)
@@ -51,13 +51,13 @@ fn helper<'a, 'tcx>(loan_path: &'a LoanPath<'tcx>) -> Option<&'a LoanPath<'tcx>>
         match loan_path.kind {
             LpVar(_) | LpUpvar(_) => None,
             LpExtend(ref lp_base, _, LpDeref(mc::Unique)) => {
-                match helper(&**lp_base) {
+                match helper(&lp_base) {
                     v @ Some(_) => v,
-                    None => Some(&**lp_base)
+                    None => Some(&lp_base)
                 }
             }
             LpDowncast(ref lp_base, _) |
-            LpExtend(ref lp_base, _, _) => helper(&**lp_base)
+            LpExtend(ref lp_base, _, _) => helper(&lp_base)
         }
     }
 }
@@ -319,7 +319,7 @@ fn each_in_scope_loan_affecting_path<F>(&self,
                 }
                 LpDowncast(ref lp_base, _) |
                 LpExtend(ref lp_base, _, _) => {
-                    loan_path = &**lp_base;
+                    loan_path = &lp_base;
                 }
             }
 
@@ -442,21 +442,21 @@ pub fn report_error_if_loan_conflicts_with_restriction(&self,
             //     borrow prevents subsequent moves, borrows, or modification of `x` until the
             //     borrow ends
 
-            let common = new_loan.loan_path.common(&*old_loan.loan_path);
+            let common = new_loan.loan_path.common(&old_loan.loan_path);
             let (nl, ol, new_loan_msg, old_loan_msg) =
-                if new_loan.loan_path.has_fork(&*old_loan.loan_path) && common.is_some() {
+                if new_loan.loan_path.has_fork(&old_loan.loan_path) && common.is_some() {
                     let nl = self.bccx.loan_path_to_string(&common.unwrap());
                     let ol = nl.clone();
                     let new_loan_msg = format!(" (here through borrowing `{}`)",
                                                self.bccx.loan_path_to_string(
-                                                   &*new_loan.loan_path));
+                                                   &new_loan.loan_path));
                     let old_loan_msg = format!(" (through borrowing `{}`)",
                                                self.bccx.loan_path_to_string(
-                                                   &*old_loan.loan_path));
+                                                   &old_loan.loan_path));
                     (nl, ol, new_loan_msg, old_loan_msg)
                 } else {
-                    (self.bccx.loan_path_to_string(&*new_loan.loan_path),
-                     self.bccx.loan_path_to_string(&*old_loan.loan_path),
+                    (self.bccx.loan_path_to_string(&new_loan.loan_path),
+                     self.bccx.loan_path_to_string(&old_loan.loan_path),
                      String::new(), String::new())
                 };
 
@@ -578,7 +578,7 @@ fn consume_common(&self,
             Some(lp) => {
                 let moved_value_use_kind = match mode {
                     euv::Copy => {
-                        self.check_for_copy_of_frozen_path(id, span, &*lp);
+                        self.check_for_copy_of_frozen_path(id, span, &lp);
                         MovedInUse
                     }
                     euv::Move(_) => {
@@ -593,7 +593,7 @@ fn consume_common(&self,
                             }
                             Some(move_kind) => {
                                 self.check_for_move_of_borrowed_path(id, span,
-                                                                     &*lp, move_kind);
+                                                                     &lp, move_kind);
                                 if move_kind == move_data::Captured {
                                     MovedInCapture
                                 } else {
@@ -622,7 +622,7 @@ fn check_for_copy_of_frozen_path(&self,
                                  &self.bccx.loan_path_to_string(copy_path))
                     .span_note(loan_span,
                                &format!("borrow of `{}` occurs here",
-                                       &self.bccx.loan_path_to_string(&*loan_path))
+                                       &self.bccx.loan_path_to_string(&loan_path))
                                )
                     .emit();
             }
@@ -656,7 +656,7 @@ fn check_for_move_of_borrowed_path(&self,
                 err.span_note(
                     loan_span,
                     &format!("borrow of `{}` occurs here",
-                            &self.bccx.loan_path_to_string(&*loan_path))
+                            &self.bccx.loan_path_to_string(&loan_path))
                     );
                 err.emit();
             }
@@ -706,7 +706,7 @@ fn check_if_path_is_moved(&self,
             self.bccx.report_use_of_moved_value(
                 span,
                 use_kind,
-                &**lp,
+                &lp,
                 the_move,
                 moved_lp,
                 self.param_env);
@@ -760,7 +760,7 @@ fn check_if_assigned_path_is_moved(&self,
                             self.bccx
                                 .report_partial_reinitialization_of_uninitialized_structure(
                                     span,
-                                    &*loan_path);
+                                    &loan_path);
                             false
                         });
                         return;
@@ -790,8 +790,8 @@ fn check_assignment(&self,
         // Check that we don't invalidate any outstanding loans
         if let Some(loan_path) = opt_loan_path(&assignee_cmt) {
             let scope = self.tcx().region_maps.node_extent(assignment_id);
-            self.each_in_scope_loan_affecting_path(scope, &*loan_path, |loan| {
-                self.report_illegal_mutation(assignment_span, &*loan_path, loan);
+            self.each_in_scope_loan_affecting_path(scope, &loan_path, |loan| {
+                self.report_illegal_mutation(assignment_span, &loan_path, loan);
                 false
             });
         }
@@ -807,7 +807,7 @@ fn check_assignment(&self,
                 } else {
                     self.bccx.report_reassigned_immutable_variable(
                         assignment_span,
-                        &*lp,
+                        &lp,
                         assign);
                 }
                 false
index 8cf10cb9b05a030b8a41f7739a75f493170d1434..38157d04a5d6d605f475579eecf6479763a2d76d 100644 (file)
@@ -386,11 +386,11 @@ fn guarantee_valid(&mut self,
                 let gen_scope = self.compute_gen_scope(borrow_scope, loan_scope);
                 debug!("gen_scope = {:?}", gen_scope);
 
-                let kill_scope = self.compute_kill_scope(loan_scope, &*loan_path);
+                let kill_scope = self.compute_kill_scope(loan_scope, &loan_path);
                 debug!("kill_scope = {:?}", kill_scope);
 
                 if req_kind == ty::MutBorrow {
-                    self.mark_loan_path_as_mutated(&*loan_path);
+                    self.mark_loan_path_as_mutated(&loan_path);
                 }
 
                 Loan {
@@ -452,7 +452,7 @@ pub fn mark_loan_path_as_mutated(&self, loan_path: &LoanPath) {
             LpDowncast(ref base, _) |
             LpExtend(ref base, mc::McInherited, _) |
             LpExtend(ref base, mc::McDeclared, _) => {
-                self.mark_loan_path_as_mutated(&**base);
+                self.mark_loan_path_as_mutated(&base);
             }
             LpExtend(_, mc::McImmutable, _) => {
                 // Nothing to do.
@@ -527,7 +527,7 @@ fn visit_expr(&mut self, ex: &Expr) {
         if let hir::ExprAddrOf(mutbl, ref base) = ex.node {
             let infcx = infer::new_infer_ctxt(self.bccx.tcx, &self.bccx.tcx.tables, None);
             let mc = mc::MemCategorizationContext::new(&infcx);
-            let base_cmt = mc.cat_expr(&**base).unwrap();
+            let base_cmt = mc.cat_expr(&base).unwrap();
             let borrow_kind = ty::BorrowKind::from_mutbl(mutbl);
             // Check that we don't allow borrows of unsafe static items.
             if check_aliasability(self.bccx, ex.span,
index 3ca9a176864852d922f3fa527fdcc65fd49b993e..1fa36a98ec5d975f42d211024aca0ceded036cf2 100644 (file)
@@ -85,14 +85,14 @@ fn visit_item(&mut self, item: &hir::Item) {
 
     fn visit_trait_item(&mut self, ti: &hir::TraitItem) {
         if let hir::ConstTraitItem(_, Some(ref expr)) = ti.node {
-            gather_loans::gather_loans_in_static_initializer(self, &*expr);
+            gather_loans::gather_loans_in_static_initializer(self, &expr);
         }
         intravisit::walk_trait_item(self, ti);
     }
 
     fn visit_impl_item(&mut self, ii: &hir::ImplItem) {
         if let hir::ImplItemKind::Const(_, ref expr) = ii.node {
-            gather_loans::gather_loans_in_static_initializer(self, &*expr);
+            gather_loans::gather_loans_in_static_initializer(self, &expr);
         }
         intravisit::walk_impl_item(self, ii);
     }
@@ -139,7 +139,7 @@ fn borrowck_item(this: &mut BorrowckCtxt, item: &hir::Item) {
     match item.node {
         hir::ItemStatic(_, _, ref ex) |
         hir::ItemConst(_, ref ex) => {
-            gather_loans::gather_loans_in_static_initializer(this, &**ex);
+            gather_loans::gather_loans_in_static_initializer(this, &ex);
         }
         _ => { }
     }
@@ -251,9 +251,9 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>(
 
     let dataflow_data = build_borrowck_dataflow_data(&mut bccx,
                                                      fn_parts.kind,
-                                                     &*fn_parts.decl,
+                                                     &fn_parts.decl,
                                                      cfg,
-                                                     &*fn_parts.body,
+                                                     &fn_parts.body,
                                                      fn_parts.span,
                                                      fn_parts.id);
 
@@ -426,12 +426,12 @@ fn has_fork(&self, other: &LoanPath<'tcx>) -> bool {
             (&LpExtend(ref base, _, LpInterior(opt_variant_id, id)),
              &LpExtend(ref base2, _, LpInterior(opt_variant_id2, id2))) =>
                 if id == id2 && opt_variant_id == opt_variant_id2 {
-                    base.has_fork(&**base2)
+                    base.has_fork(&base2)
                 } else {
                     true
                 },
             (&LpExtend(ref base, _, LpDeref(_)), _) => base.has_fork(other),
-            (_, &LpExtend(ref base, _, LpDeref(_))) => self.has_fork(&**base),
+            (_, &LpExtend(ref base, _, LpDeref(_))) => self.has_fork(&base),
             _ => false,
         }
     }
@@ -449,7 +449,7 @@ fn common(&self, other: &LoanPath<'tcx>) -> Option<LoanPath<'tcx>> {
             (&LpExtend(ref base, a, LpInterior(opt_variant_id, id)),
              &LpExtend(ref base2, _, LpInterior(opt_variant_id2, id2))) => {
                 if id == id2 && opt_variant_id == opt_variant_id2 {
-                    base.common(&**base2).map(|x| {
+                    base.common(&base2).map(|x| {
                         let xd = x.depth();
                         if base.depth() == xd && base2.depth() == xd {
                             assert_eq!(base.ty, base2.ty);
@@ -463,11 +463,11 @@ fn common(&self, other: &LoanPath<'tcx>) -> Option<LoanPath<'tcx>> {
                         }
                     })
                 } else {
-                    base.common(&**base2)
+                    base.common(&base2)
                 }
             }
             (&LpExtend(ref base, _, LpDeref(_)), _) => base.common(other),
-            (_, &LpExtend(ref other, _, LpDeref(_))) => self.common(&**other),
+            (_, &LpExtend(ref other, _, LpDeref(_))) => self.common(&other),
             (&LpVar(id), &LpVar(id2)) => {
                 if id == id2 {
                     assert_eq!(self.ty, other.ty);
@@ -673,7 +673,7 @@ pub fn report_use_of_moved_value<'b>(&self,
                                                      .map
                                                      .find(the_move.id) {
                     Some(hir_map::NodeExpr(expr)) => {
-                        (self.tcx.expr_ty_adjusted(&*expr), expr.span)
+                        (self.tcx.expr_ty_adjusted(&expr), expr.span)
                     }
                     r => {
                         self.tcx.sess.bug(&format!("MoveExpr({}) maps to \
@@ -735,7 +735,7 @@ pub fn report_use_of_moved_value<'b>(&self,
                                                      .map
                                                      .find(the_move.id) {
                     Some(hir_map::NodeExpr(expr)) => {
-                        (self.tcx.expr_ty_adjusted(&*expr), expr.span)
+                        (self.tcx.expr_ty_adjusted(&expr), expr.span)
                     }
                     r => {
                         self.tcx.sess.bug(&format!("Captured({}) maps to \
@@ -833,19 +833,19 @@ pub fn bckerr_to_string(&self, err: &BckError<'tcx>) -> String {
             err_mutbl => {
                 let descr = match err.cmt.note {
                     mc::NoteClosureEnv(_) | mc::NoteUpvarRef(_) => {
-                        self.cmt_to_string(&*err.cmt)
+                        self.cmt_to_string(&err.cmt)
                     }
                     _ => match opt_loan_path(&err.cmt) {
                         None => {
                             format!("{} {}",
                                     err.cmt.mutbl.to_user_str(),
-                                    self.cmt_to_string(&*err.cmt))
+                                    self.cmt_to_string(&err.cmt))
                         }
                         Some(lp) => {
                             format!("{} {} `{}`",
                                     err.cmt.mutbl.to_user_str(),
-                                    self.cmt_to_string(&*err.cmt),
-                                    self.loan_path_to_string(&*lp))
+                                    self.cmt_to_string(&err.cmt),
+                                    self.loan_path_to_string(&lp))
                         }
                     }
                 };
@@ -876,7 +876,7 @@ pub fn bckerr_to_string(&self, err: &BckError<'tcx>) -> String {
                 let msg = match opt_loan_path(&err.cmt) {
                     None => "borrowed value".to_string(),
                     Some(lp) => {
-                        format!("`{}`", self.loan_path_to_string(&*lp))
+                        format!("`{}`", self.loan_path_to_string(&lp))
                     }
                 };
                 format!("{} does not live long enough", msg)
@@ -1051,9 +1051,9 @@ pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<
             err_borrowed_pointer_too_short(loan_scope, ptr_scope) => {
                 let descr = match opt_loan_path(&err.cmt) {
                     Some(lp) => {
-                        format!("`{}`", self.loan_path_to_string(&*lp))
+                        format!("`{}`", self.loan_path_to_string(&lp))
                     }
-                    None => self.cmt_to_string(&*err.cmt),
+                    None => self.cmt_to_string(&err.cmt),
                 };
                 self.tcx.note_and_explain_region(
                     db,
@@ -1081,7 +1081,7 @@ pub fn append_loan_path_to_string(&self,
 
             LpDowncast(ref lp_base, variant_def_id) => {
                 out.push('(');
-                self.append_loan_path_to_string(&**lp_base, out);
+                self.append_loan_path_to_string(&lp_base, out);
                 out.push_str(DOWNCAST_PRINTED_OPERATOR);
                 out.push_str(&self.tcx.item_path_str(variant_def_id));
                 out.push(')');
@@ -1089,7 +1089,7 @@ pub fn append_loan_path_to_string(&self,
 
 
             LpExtend(ref lp_base, _, LpInterior(_, InteriorField(fname))) => {
-                self.append_autoderefd_loan_path_to_string(&**lp_base, out);
+                self.append_autoderefd_loan_path_to_string(&lp_base, out);
                 match fname {
                     mc::NamedField(fname) => {
                         out.push('.');
@@ -1103,13 +1103,13 @@ pub fn append_loan_path_to_string(&self,
             }
 
             LpExtend(ref lp_base, _, LpInterior(_, InteriorElement(..))) => {
-                self.append_autoderefd_loan_path_to_string(&**lp_base, out);
+                self.append_autoderefd_loan_path_to_string(&lp_base, out);
                 out.push_str("[..]");
             }
 
             LpExtend(ref lp_base, _, LpDeref(_)) => {
                 out.push('*');
-                self.append_loan_path_to_string(&**lp_base, out);
+                self.append_loan_path_to_string(&lp_base, out);
             }
         }
     }
@@ -1122,12 +1122,12 @@ pub fn append_autoderefd_loan_path_to_string(&self,
                 // For a path like `(*x).f` or `(*x)[3]`, autoderef
                 // rules would normally allow users to omit the `*x`.
                 // So just serialize such paths to `x.f` or x[3]` respectively.
-                self.append_autoderefd_loan_path_to_string(&**lp_base, out)
+                self.append_autoderefd_loan_path_to_string(&lp_base, out)
             }
 
             LpDowncast(ref lp_base, variant_def_id) => {
                 out.push('(');
-                self.append_autoderefd_loan_path_to_string(&**lp_base, out);
+                self.append_autoderefd_loan_path_to_string(&lp_base, out);
                 out.push(':');
                 out.push_str(&self.tcx.item_path_str(variant_def_id));
                 out.push(')');
index 735e618cc732b1f0da607b438e7e58c57de0369c..cbec32e358d81fbad18e71443939b3b3a9c43d15 100644 (file)
@@ -207,7 +207,7 @@ fn loan_path_is_precise(loan_path: &LoanPath) -> bool {
         }
         LpDowncast(ref lp_base, _) |
         LpExtend(ref lp_base, _, _) => {
-            loan_path_is_precise(&**lp_base)
+            loan_path_is_precise(&lp_base)
         }
     }
 }
@@ -587,7 +587,7 @@ fn kill_moves(&self,
         // assignment referring to another location.
 
         let loan_path = self.path_loan_path(path);
-        if loan_path_is_precise(&*loan_path) {
+        if loan_path_is_precise(&loan_path) {
             self.each_applicable_move(path, |move_index| {
                 debug!("kill_moves add_kill {:?} kill_id={} move_index={}",
                        kill_kind, kill_id, move_index.get());
@@ -700,7 +700,7 @@ pub fn each_move_of<F>(&self,
             if base_indices.iter().any(|x| x == &moved_path) {
                 // Scenario 1 or 2: `loan_path` or some base path of
                 // `loan_path` was moved.
-                if !f(the_move, &*self.move_data.path_loan_path(moved_path)) {
+                if !f(the_move, &self.move_data.path_loan_path(moved_path)) {
                     ret = false;
                 }
             } else {
@@ -710,7 +710,7 @@ pub fn each_move_of<F>(&self,
                             // Scenario 3: some extension of `loan_path`
                             // was moved
                             f(the_move,
-                              &*self.move_data.path_loan_path(moved_path))
+                              &self.move_data.path_loan_path(moved_path))
                         } else {
                             true
                         }
index eb63f572649a3fada48619c3de97780c4f7f941d..7a5491cdbe7f3cd612a36456fd95d0090df018fd 100644 (file)
@@ -87,7 +87,7 @@ fn build_set<O:DataFlowOperator, F>(&self,
             if saw_some {
                 set.push_str(", ");
             }
-            let loan_str = self.borrowck_ctxt.loan_path_to_string(&*lp);
+            let loan_str = self.borrowck_ctxt.loan_path_to_string(&lp);
             set.push_str(&loan_str[..]);
             saw_some = true;
             true