]> git.lizzy.rs Git - rust.git/commitdiff
typeck: don't wastefully clone expressions for cast checks.
authorEduard Burtescu <edy.burt@gmail.com>
Sun, 21 Feb 2016 19:39:32 +0000 (21:39 +0200)
committerEduard Burtescu <edy.burt@gmail.com>
Wed, 9 Mar 2016 14:45:29 +0000 (16:45 +0200)
src/librustc_typeck/check/cast.rs
src/librustc_typeck/check/mod.rs

index 087665663232421c8321f77efd7d09a685e5430b..6468713d07aab5ce40a3aa00973194a4f1217bfd 100644 (file)
@@ -55,7 +55,7 @@
 /// Reifies a cast check to be checked once we have full type information for
 /// a function context.
 pub struct CastCheck<'tcx> {
-    expr: hir::Expr,
+    expr: &'tcx hir::Expr,
     expr_ty: Ty<'tcx>,
     cast_ty: Ty<'tcx>,
     span: Span,
@@ -109,7 +109,7 @@ enum CastError {
 }
 
 impl<'tcx> CastCheck<'tcx> {
-    pub fn new(expr: hir::Expr, expr_ty: Ty<'tcx>, cast_ty: Ty<'tcx>, span: Span)
+    pub fn new(expr: &'tcx hir::Expr, expr_ty: Ty<'tcx>, cast_ty: Ty<'tcx>, span: Span)
                -> CastCheck<'tcx> {
         CastCheck {
             expr: expr,
@@ -239,7 +239,7 @@ fn do_check<'a>(&self, fcx: &FnCtxt<'a, 'tcx>) -> Result<CastKind, CastError> {
             (None, Some(t_cast)) => {
                 if let ty::TyFnDef(_, _, f) = self.expr_ty.sty {
                     // Attempt a coercion to a fn pointer type.
-                    let res = coercion::try(fcx, &self.expr,
+                    let res = coercion::try(fcx, self.expr,
                         self.expr_ty, fcx.tcx().mk_ty(ty::TyFnPtr(f)));
                     if !res.is_ok() {
                         return Err(CastError::NonScalar);
@@ -390,7 +390,7 @@ fn check_addr_ptr_cast<'a>(&self,
     }
 
     fn try_coercion_cast<'a>(&self, fcx: &FnCtxt<'a, 'tcx>) -> bool {
-        coercion::try(fcx, &self.expr, self.expr_ty, self.cast_ty).is_ok()
+        coercion::try(fcx, self.expr, self.expr_ty, self.cast_ty).is_ok()
     }
 
 }
index e3578559c9b66b51067937cb8cabde518377455f..1c0430f0b7cef2f199bc65fcb43e7a7f677d74b2 100644 (file)
@@ -1701,6 +1701,8 @@ pub fn add_obligations_for_parameters(&self,
     }
 
     // FIXME(arielb1): use this instead of field.ty everywhere
+    // Only for fields! Returns <none> for methods>
+    // Indifferent to privacy flags
     pub fn field_ty(&self,
                     span: Span,
                     field: ty::FieldDef<'tcx>,
@@ -1711,8 +1713,6 @@ pub fn field_ty(&self,
                                            &field.ty(self.tcx(), substs))
     }
 
-    // Only for fields! Returns <none> for methods>
-    // Indifferent to privacy flags
     fn check_casts(&self) {
         let mut deferred_cast_checks = self.inh.deferred_cast_checks.borrow_mut();
         for cast in deferred_cast_checks.drain(..) {
@@ -3511,7 +3511,7 @@ fn check_expr_struct<'a, 'tcx>(fcx: &FnCtxt<'a,'tcx>,
 
             // Defer other checks until we're done type checking.
             let mut deferred_cast_checks = fcx.inh.deferred_cast_checks.borrow_mut();
-            let cast_check = cast::CastCheck::new((**e).clone(), t_expr, t_cast, expr.span);
+            let cast_check = cast::CastCheck::new(e, t_expr, t_cast, expr.span);
             deferred_cast_checks.push(cast_check);
         }
       }