about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_trans/builder.rs77
-rw-r--r--src/librustc_trans/mir/block.rs2
2 files changed, 30 insertions, 49 deletions
diff --git a/src/librustc_trans/builder.rs b/src/librustc_trans/builder.rs
index c7de7fd3695..9f032cdbfe5 100644
--- a/src/librustc_trans/builder.rs
+++ b/src/librustc_trans/builder.rs
@@ -175,30 +175,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                    .collect::<Vec<String>>()
                    .join(", "));
 
-        if cfg!(debug_assertions) {
-            let mut fn_ty = val_ty(llfn);
-            // Strip off pointers
-            while fn_ty.kind() == llvm::TypeKind::Pointer {
-                fn_ty = fn_ty.element_type();
-            }
-
-            assert!(fn_ty.kind() == llvm::TypeKind::Function,
-                    "builder::invoke not passed a function");
-
-            let param_tys = fn_ty.func_params();
-
-            let iter = param_tys.into_iter()
-                .zip(args.iter().map(|&v| val_ty(v)));
-            for (i, (expected_ty, actual_ty)) in iter.enumerate() {
-                if expected_ty != actual_ty {
-                    bug!("Type mismatch in invoke of {:?}. \
-                      Expected {:?} for param {}, got {:?}",
-                     Value(llfn),
-                     expected_ty, i, actual_ty);
-
-                }
-            }
-        }
+        check_call("invoke", llfn, args);
 
         let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _);
 
@@ -880,30 +857,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                    .collect::<Vec<String>>()
                    .join(", "));
 
-        if cfg!(debug_assertions) {
-            let mut fn_ty = val_ty(llfn);
-            // Strip off pointers
-            while fn_ty.kind() == llvm::TypeKind::Pointer {
-                fn_ty = fn_ty.element_type();
-            }
-
-            assert!(fn_ty.kind() == llvm::TypeKind::Function,
-                    "builder::call not passed a function");
-
-            let param_tys = fn_ty.func_params();
-
-            let iter = param_tys.into_iter()
-                .zip(args.iter().map(|&v| val_ty(v)));
-            for (i, (expected_ty, actual_ty)) in iter.enumerate() {
-                if expected_ty != actual_ty {
-                    bug!("Type mismatch in function call of {:?}. \
-                      Expected {:?} for param {}, got {:?}",
-                     Value(llfn),
-                     expected_ty, i, actual_ty);
-
-                }
-            }
-        }
+        check_call("call", llfn, args);
 
         let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _);
 
@@ -1147,3 +1101,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
         }
     }
 }
+
+fn check_call(typ: &str, llfn: ValueRef, args: &[ValueRef]) {
+    if cfg!(debug_assertions) {
+        let mut fn_ty = val_ty(llfn);
+        // Strip off pointers
+        while fn_ty.kind() == llvm::TypeKind::Pointer {
+            fn_ty = fn_ty.element_type();
+        }
+
+        assert!(fn_ty.kind() == llvm::TypeKind::Function,
+                "builder::{} not passed a function", typ);
+
+        let param_tys = fn_ty.func_params();
+
+        let iter = param_tys.into_iter()
+            .zip(args.iter().map(|&v| val_ty(v)));
+        for (i, (expected_ty, actual_ty)) in iter.enumerate() {
+            if expected_ty != actual_ty {
+                bug!("Type mismatch in function call of {:?}. \
+                      Expected {:?} for param {}, got {:?}",
+                     Value(llfn),
+                     expected_ty, i, actual_ty);
+
+            }
+        }
+    }
+}
diff --git a/src/librustc_trans/mir/block.rs b/src/librustc_trans/mir/block.rs
index d6a42bea22a..d0b47934bcf 100644
--- a/src/librustc_trans/mir/block.rs
+++ b/src/librustc_trans/mir/block.rs
@@ -444,7 +444,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
                            "bad final argument to \"rust-call\" fn {:?}", tuple.ty)
         };
 
-        // Handle both by-ref and immediate tuples. This gives us the option of
+        // Handle both by-ref and immediate tuples.
         match tuple.val {
             Ref(llval) => {
                 let base_repr = adt::represent_type(bcx.ccx(), tuple.ty);