]> git.lizzy.rs Git - rust.git/commitdiff
Move simd_ffi gating from trans to typeck.
authorEduard Burtescu <edy.burt@gmail.com>
Tue, 23 Feb 2016 19:06:32 +0000 (21:06 +0200)
committerEduard Burtescu <edy.burt@gmail.com>
Thu, 17 Mar 2016 15:51:58 +0000 (17:51 +0200)
src/librustc_trans/trans/foreign.rs
src/librustc_typeck/collect.rs

index 8e728ca808ccbcb42a8d24e173c3bf37f1af4b28..37de40efd3ddd9468c2c4a7565b62630647a472e 100644 (file)
@@ -463,30 +463,6 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
     return bcx;
 }
 
-// feature gate SIMD types in FFI, since I (huonw) am not sure the
-// ABIs are handled at all correctly.
-fn gate_simd_ffi(tcx: &TyCtxt, decl: &hir::FnDecl, ty: &ty::BareFnTy) {
-    if !tcx.sess.features.borrow().simd_ffi {
-        let check = |ast_ty: &hir::Ty, ty: ty::Ty| {
-            if ty.is_simd() {
-                tcx.sess.struct_span_err(ast_ty.span,
-                              &format!("use of SIMD type `{}` in FFI is highly experimental and \
-                                        may result in invalid code",
-                                       pprust::ty_to_string(ast_ty)))
-                    .fileline_help(ast_ty.span,
-                                   "add #![feature(simd_ffi)] to the crate attributes to enable")
-                    .emit();
-            }
-        };
-        let sig = &ty.sig.0;
-        for (input, ty) in decl.inputs.iter().zip(&sig.inputs) {
-            check(&input.ty, *ty)
-        }
-        if let hir::Return(ref ty) = decl.output {
-            check(&ty, sig.output.unwrap())
-        }
-    }
-}
 
 pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &hir::ForeignMod) {
     let _icx = push_ctxt("foreign::trans_foreign_mod");
@@ -498,13 +474,6 @@ pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &hir::ForeignMod) {
                 Abi::Rust | Abi::RustIntrinsic | Abi::PlatformIntrinsic => {}
                 abi => {
                     let ty = ccx.tcx().node_id_to_type(foreign_item.id);
-                    match ty.sty {
-                        ty::TyFnDef(_, _, bft) |
-                        ty::TyFnPtr(bft) => gate_simd_ffi(ccx.tcx(), &decl, bft),
-                        _ => ccx.tcx().sess.span_bug(foreign_item.span,
-                                                     "foreign fn's sty isn't a bare_fn_ty?")
-                    }
-
                     register_foreign_item_fn(ccx, abi, ty, &lname, &foreign_item.attrs);
                     // Unlike for other items, we shouldn't call
                     // `base::update_linkage` here.  Foreign items have
index 0f88640b629510040efdab8a9fa7c1c9638a7f17..258c7af1316eb1b9d5bf72466840fc1bda1c5029 100644 (file)
@@ -2155,7 +2155,7 @@ fn compute_type_scheme_of_foreign_fn_decl<'a, 'tcx>(
     let input_tys = decl.inputs
                         .iter()
                         .map(|a| ty_of_arg(&ccx.icx(ast_generics), &rb, a, None))
-                        .collect();
+                        .collect::<Vec<_>>();
 
     let output = match decl.output {
         hir::Return(ref ty) =>
@@ -2166,6 +2166,29 @@ fn compute_type_scheme_of_foreign_fn_decl<'a, 'tcx>(
             ty::FnDiverging
     };
 
+    // feature gate SIMD types in FFI, since I (huonw) am not sure the
+    // ABIs are handled at all correctly.
+    if abi != abi::Abi::RustIntrinsic && abi != abi::Abi::PlatformIntrinsic
+            && !ccx.tcx.sess.features.borrow().simd_ffi {
+        let check = |ast_ty: &hir::Ty, ty: ty::Ty| {
+            if ty.is_simd() {
+                ccx.tcx.sess.struct_span_err(ast_ty.span,
+                              &format!("use of SIMD type `{}` in FFI is highly experimental and \
+                                        may result in invalid code",
+                                       pprust::ty_to_string(ast_ty)))
+                    .fileline_help(ast_ty.span,
+                                   "add #![feature(simd_ffi)] to the crate attributes to enable")
+                    .emit();
+            }
+        };
+        for (input, ty) in decl.inputs.iter().zip(&input_tys) {
+            check(&input.ty, ty)
+        }
+        if let hir::Return(ref ty) = decl.output {
+            check(&ty, output.unwrap())
+        }
+    }
+
     let substs = ccx.tcx.mk_substs(mk_item_substs(ccx, &ty_generics));
     let t_fn = ccx.tcx.mk_fn_def(id, substs, ty::BareFnTy {
         abi: abi,