]> git.lizzy.rs Git - rust.git/commitdiff
Revert "Auto merge of #65134 - davidtwco:issue-19834-improper-ctypes-in-extern-C...
authorRobin Kruppe <robin.kruppe@gmail.com>
Wed, 13 Nov 2019 16:00:47 +0000 (17:00 +0100)
committerRobin Kruppe <robin.kruppe@gmail.com>
Wed, 13 Nov 2019 16:00:47 +0000 (17:00 +0100)
This reverts commit 3f0e16473de5ec010f44290a8c3ea1d90e0ad7a2, reversing
changes made to 61a551b4939ec1d5596e585351038b8fbd0124ba.

18 files changed:
src/libpanic_abort/lib.rs
src/libpanic_unwind/lib.rs
src/librustc_codegen_llvm/back/write.rs
src/librustc_codegen_llvm/llvm/mod.rs
src/librustc_lint/types.rs
src/libstd/sys/sgx/abi/mod.rs
src/libstd/sys/sgx/rwlock.rs
src/test/ui/abi/abi-sysv64-register-usage.rs
src/test/ui/align-with-extern-c-fn.rs
src/test/ui/issues/issue-16441.rs
src/test/ui/issues/issue-26997.rs
src/test/ui/issues/issue-28600.rs
src/test/ui/issues/issue-38763.rs
src/test/ui/issues/issue-51907.rs
src/test/ui/lint/lint-ctypes-fn.rs [deleted file]
src/test/ui/lint/lint-ctypes-fn.stderr [deleted file]
src/test/ui/mir/mir_cast_fn_ret.rs
src/test/ui/mir/mir_codegen_calls.rs

index bc9dd2edaf21174b4588b66cf05e5951ef5c8278..5509f47bc8858ccdc5a668f71cf9f4f001ab32ff 100644 (file)
@@ -21,7 +21,6 @@
 // Rust's "try" function, but if we're aborting on panics we just call the
 // function as there's nothing else we need to do here.
 #[rustc_std_internal_symbol]
-#[allow(improper_ctypes)]
 pub unsafe extern fn __rust_maybe_catch_panic(f: fn(*mut u8),
                                               data: *mut u8,
                                               _data_ptr: *mut usize,
index 4c6c728f6f7d4e2c00ba3c6dfd141dab49d777f2..d97a7a8a87d8d20ae244cc0585d9614e6bd6218f 100644 (file)
@@ -72,7 +72,6 @@
 // hairy and tightly coupled, for more information see the compiler's
 // implementation of this.
 #[no_mangle]
-#[allow(improper_ctypes)]
 pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
                                                   data: *mut u8,
                                                   data_ptr: *mut usize,
index e5a5d05ba5ec7920d52f5af4925f2b9ec236cb81..fa14ce7b03c8ca69a215187cceefe170609f3d9f 100644 (file)
@@ -240,7 +240,9 @@ fn drop(&mut self) {
     }
 }
 
-fn report_inline_asm(cgcx: &CodegenContext<LlvmCodegenBackend>, msg: &str, cookie: c_uint) {
+unsafe extern "C" fn report_inline_asm(cgcx: &CodegenContext<LlvmCodegenBackend>,
+                                       msg: &str,
+                                       cookie: c_uint) {
     cgcx.diag_emitter.inline_asm_error(cookie as u32, msg.to_owned());
 }
 
index e49462674b3c280249255c6f0f5e950226867078..57815933af02b2961b52bc79a87cc84199a3ae07 100644 (file)
@@ -87,7 +87,6 @@ pub struct RustString {
 }
 
 /// Appending to a Rust string -- used by RawRustStringOstream.
-#[allow(improper_ctypes)]
 #[no_mangle]
 pub unsafe extern "C" fn LLVMRustStringWriteImpl(sr: &RustString,
                                                  ptr: *const c_char,
index 65e0940920bd741a3babfa0f4e7027c83aca450a..9a4e981081fcfcd309411795bc7370dfc324e101 100644 (file)
@@ -4,7 +4,7 @@
 use crate::hir::def_id::DefId;
 use rustc::hir::lowering::is_range_literal;
 use rustc::ty::subst::SubstsRef;
-use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt, TypeFoldable};
+use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
 use rustc::ty::layout::{self, IntegerExt, LayoutOf, VariantIdx, SizeSkeleton};
 use rustc::{lint, util};
 use rustc_index::vec::Idx;
@@ -837,13 +837,16 @@ fn check_type_for_ffi(&self,
             ty::Array(ty, _) => self.check_type_for_ffi(cache, ty),
 
             ty::FnPtr(sig) => {
-                if self.is_internal_abi(sig.abi()) {
-                    return FfiUnsafe {
-                        ty,
-                        reason: "this function pointer has Rust-specific calling convention",
-                        help: Some("consider using an `extern fn(...) -> ...` \
-                                    function pointer instead"),
-                    };
+                match sig.abi() {
+                    Abi::Rust | Abi::RustIntrinsic | Abi::PlatformIntrinsic | Abi::RustCall => {
+                        return FfiUnsafe {
+                            ty,
+                            reason: "this function pointer has Rust-specific calling convention",
+                            help: Some("consider using an `extern fn(...) -> ...` \
+                                        function pointer instead"),
+                        }
+                    }
+                    _ => {}
                 }
 
                 let sig = cx.erase_late_bound_regions(&sig);
@@ -870,10 +873,7 @@ fn check_type_for_ffi(&self,
 
             ty::Foreign(..) => FfiSafe,
 
-            // `extern "C" fn` functions can have type parameters, which may or may not be FFI-safe,
-            //  so they are currently ignored for the purposes of this lint, see #65134.
-            ty::Param(..) | ty::Projection(..) => FfiSafe,
-
+            ty::Param(..) |
             ty::Infer(..) |
             ty::Bound(..) |
             ty::Error |
@@ -882,6 +882,7 @@ fn check_type_for_ffi(&self,
             ty::GeneratorWitness(..) |
             ty::Placeholder(..) |
             ty::UnnormalizedProjection(..) |
+            ty::Projection(..) |
             ty::Opaque(..) |
             ty::FnDef(..) => bug!("unexpected type in foreign function: {:?}", ty),
         }
@@ -893,16 +894,11 @@ fn emit_ffi_unsafe_type_lint(
         sp: Span,
         note: &str,
         help: Option<&str>,
-        is_foreign_item: bool,
     ) {
         let mut diag = self.cx.struct_span_lint(
             IMPROPER_CTYPES,
             sp,
-            &format!(
-                "`extern` {} uses type `{}`, which is not FFI-safe",
-                if is_foreign_item { "block" } else { "fn" },
-                ty,
-            ),
+            &format!("`extern` block uses type `{}`, which is not FFI-safe", ty),
         );
         diag.span_label(sp, "not FFI-safe");
         if let Some(help) = help {
@@ -917,7 +913,9 @@ fn emit_ffi_unsafe_type_lint(
         diag.emit();
     }
 
-    fn check_for_opaque_ty(&mut self, sp: Span, ty: Ty<'tcx>, is_foreign_item: bool) -> bool {
+    fn check_for_opaque_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool {
+        use crate::rustc::ty::TypeFoldable;
+
         struct ProhibitOpaqueTypes<'tcx> {
             ty: Option<Ty<'tcx>>,
         };
@@ -941,7 +939,6 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool {
                 sp,
                 "opaque types have no C equivalent",
                 None,
-                is_foreign_item,
             );
             true
         } else {
@@ -949,46 +946,42 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool {
         }
     }
 
-    fn check_type_for_ffi_and_report_errors(
-        &mut self,
-        sp: Span,
-        ty: Ty<'tcx>,
-        is_foreign_item: bool,
-    ) {
+    fn check_type_for_ffi_and_report_errors(&mut self, sp: Span, ty: Ty<'tcx>) {
         // We have to check for opaque types before `normalize_erasing_regions`,
         // which will replace opaque types with their underlying concrete type.
-        if self.check_for_opaque_ty(sp, ty, is_foreign_item) {
+        if self.check_for_opaque_ty(sp, ty) {
             // We've already emitted an error due to an opaque type.
             return;
         }
 
-        let ty = self.cx.tcx.normalize_erasing_regions(self.cx.param_env, ty);
+        // it is only OK to use this function because extern fns cannot have
+        // any generic types right now:
+        let ty = self.cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
+
         match self.check_type_for_ffi(&mut FxHashSet::default(), ty) {
             FfiResult::FfiSafe => {}
             FfiResult::FfiPhantom(ty) => {
-                self.emit_ffi_unsafe_type_lint(
-                    ty, sp, "composed only of `PhantomData`", None, is_foreign_item);
+                self.emit_ffi_unsafe_type_lint(ty, sp, "composed only of `PhantomData`", None);
             }
             FfiResult::FfiUnsafe { ty, reason, help } => {
-                self.emit_ffi_unsafe_type_lint(
-                    ty, sp, reason, help, is_foreign_item);
+                self.emit_ffi_unsafe_type_lint(ty, sp, reason, help);
             }
         }
     }
 
-    fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl, is_foreign_item: bool) {
+    fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl) {
         let def_id = self.cx.tcx.hir().local_def_id(id);
         let sig = self.cx.tcx.fn_sig(def_id);
         let sig = self.cx.tcx.erase_late_bound_regions(&sig);
 
         for (input_ty, input_hir) in sig.inputs().iter().zip(&decl.inputs) {
-            self.check_type_for_ffi_and_report_errors(input_hir.span, input_ty, is_foreign_item);
+            self.check_type_for_ffi_and_report_errors(input_hir.span, input_ty);
         }
 
         if let hir::Return(ref ret_hir) = decl.output {
             let ret_ty = sig.output();
             if !ret_ty.is_unit() {
-                self.check_type_for_ffi_and_report_errors(ret_hir.span, ret_ty, is_foreign_item);
+                self.check_type_for_ffi_and_report_errors(ret_hir.span, ret_ty);
             }
         }
     }
@@ -996,15 +989,7 @@ fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl, is_foreign_it
     fn check_foreign_static(&mut self, id: hir::HirId, span: Span) {
         let def_id = self.cx.tcx.hir().local_def_id(id);
         let ty = self.cx.tcx.type_of(def_id);
-        self.check_type_for_ffi_and_report_errors(span, ty, true);
-    }
-
-    fn is_internal_abi(&self, abi: Abi) -> bool {
-        if let Abi::Rust | Abi::RustCall | Abi::RustIntrinsic | Abi::PlatformIntrinsic = abi {
-            true
-        } else {
-            false
-        }
+        self.check_type_for_ffi_and_report_errors(span, ty);
     }
 }
 
@@ -1012,10 +997,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes {
     fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem) {
         let mut vis = ImproperCTypesVisitor { cx };
         let abi = cx.tcx.hir().get_foreign_abi(it.hir_id);
-        if !vis.is_internal_abi(abi) {
+        if let Abi::Rust | Abi::RustCall | Abi::RustIntrinsic | Abi::PlatformIntrinsic = abi {
+            // Don't worry about types in internal ABIs.
+        } else {
             match it.kind {
                 hir::ForeignItemKind::Fn(ref decl, _, _) => {
-                    vis.check_foreign_fn(it.hir_id, decl, true);
+                    vis.check_foreign_fn(it.hir_id, decl);
                 }
                 hir::ForeignItemKind::Static(ref ty, _) => {
                     vis.check_foreign_static(it.hir_id, ty.span);
@@ -1024,29 +1011,6 @@ fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem
             }
         }
     }
-
-    fn check_fn(
-        &mut self,
-        cx: &LateContext<'a, 'tcx>,
-        kind: hir::intravisit::FnKind<'tcx>,
-        decl: &'tcx hir::FnDecl,
-        _: &'tcx hir::Body,
-        _: Span,
-        hir_id: hir::HirId,
-    ) {
-        use hir::intravisit::FnKind;
-
-        let abi = match kind {
-            FnKind::ItemFn(_, _, header, ..) => (header.abi),
-            FnKind::Method(_, sig, ..) => (sig.header.abi),
-            _ => return,
-        };
-
-        let mut vis = ImproperCTypesVisitor { cx };
-        if !vis.is_internal_abi(abi) {
-            vis.check_foreign_fn(hir_id, decl, false);
-        }
-    }
 }
 
 declare_lint_pass!(VariantSizeDifferences => [VARIANT_SIZE_DIFFERENCES]);
index 3a9b1fc86840c1c5fcb18fb0e59ee3e470bd902b..0f107de83f062c76fbea80edeb6ede41429ee79f 100644 (file)
@@ -53,7 +53,6 @@
 // (main function exists). If this is a library, the crate author should be
 // able to specify this
 #[cfg(not(test))]
-#[allow(improper_ctypes)]
 #[no_mangle]
 extern "C" fn entry(p1: u64, p2: u64, p3: u64, secondary: bool, p4: u64, p5: u64) -> (u64, u64) {
     // FIXME: how to support TLS in library mode?
index c32e6dd3786692086003c743a9c968a3933e290c..e2f94b1d928e10db38416f8c874fd88fb08c652d 100644 (file)
@@ -172,7 +172,6 @@ pub unsafe fn destroy(&self) {}
 
 #[cfg(not(test))]
 #[no_mangle]
-#[allow(improper_ctypes)]
 pub unsafe extern "C" fn __rust_rwlock_rdlock(p: *mut RWLock) -> i32 {
     if p.is_null() {
         return EINVAL;
@@ -182,7 +181,6 @@ pub unsafe fn destroy(&self) {}
 }
 
 #[cfg(not(test))]
-#[allow(improper_ctypes)]
 #[no_mangle]
 pub unsafe extern "C" fn __rust_rwlock_wrlock(p: *mut RWLock) -> i32 {
     if p.is_null() {
@@ -192,7 +190,6 @@ pub unsafe fn destroy(&self) {}
     return 0;
 }
 #[cfg(not(test))]
-#[allow(improper_ctypes)]
 #[no_mangle]
 pub unsafe extern "C" fn __rust_rwlock_unlock(p: *mut RWLock) -> i32 {
     if p.is_null() {
index 88d89fba260aa76681a1baf41ad232356cd64f5b..0c7e2d906b7c1d67e1c0bbc2ff2cfa9b92822589 100644 (file)
@@ -33,7 +33,6 @@ pub extern "sysv64" fn all_the_registers(rdi: i64, rsi: i64, rdx: i64,
 
 // this struct contains 8 i64's, while only 6 can be passed in registers.
 #[cfg(target_arch = "x86_64")]
-#[repr(C)]
 #[derive(PartialEq, Eq, Debug)]
 pub struct LargeStruct(i64, i64, i64, i64, i64, i64, i64, i64);
 
index 8ba90225c6c7fb35241de95a53976cb023063ed1..09abe4fbf7e095f96d245879ecd47a4e4f8d4bb7 100644 (file)
@@ -7,7 +7,7 @@
 
 #![feature(repr_align)]
 
-#[repr(align(16), C)]
+#[repr(align(16))]
 pub struct A(i64);
 
 pub extern "C" fn foo(x: A) {}
index 1086aeb305542b7d997157a5f9e1314605ce3aa5..bae3813f9da951b01997de7073d3c21c9837d694 100644 (file)
@@ -5,7 +5,6 @@
 struct Empty;
 
 // This used to cause an ICE
-#[allow(improper_ctypes)]
 extern "C" fn ice(_a: Empty) {}
 
 fn main() {
index 9e7e47117ac290cb6ea856f7e20e96f6b0263d2d..f6d349a38f52338729d6880a785d64298c3f5720 100644 (file)
@@ -6,7 +6,6 @@ pub struct Foo {
 }
 
 impl Foo {
-    #[allow(improper_ctypes)]
     pub extern fn foo_new() -> Foo {
         Foo { x: 21, y: 33 }
     }
index 170c0a07125e69b51362caac3c80d341734a3ba4..3bbe4ae29bdd69a45bf47919d3978eda55096291 100644 (file)
@@ -4,7 +4,6 @@
 struct Test;
 
 impl Test {
-    #[allow(improper_ctypes)]
     #[allow(dead_code)]
     #[allow(unused_variables)]
     pub extern fn test(val: &str) {
index c84846bc4e8742f3a7c9d6771cee46e7d376b209..6e6de09225f571f8391b37ab45e191c4f813411f 100644 (file)
@@ -4,7 +4,6 @@
 #[repr(C)]
 pub struct Foo(i128);
 
-#[allow(improper_ctypes)]
 #[no_mangle]
 pub extern "C" fn foo(x: Foo) -> Foo { x }
 
index 1946611a17c2f057048e58e36db0399e02739097..3691fe19117746649fa1fa33fdf88c16a8e207f9 100644 (file)
@@ -6,9 +6,7 @@ trait Foo {
 
 struct Bar;
 impl Foo for Bar {
-    #[allow(improper_ctypes)]
     extern fn borrow(&self) {}
-    #[allow(improper_ctypes)]
     extern fn take(self: Box<Self>) {}
 }
 
diff --git a/src/test/ui/lint/lint-ctypes-fn.rs b/src/test/ui/lint/lint-ctypes-fn.rs
deleted file mode 100644 (file)
index 2daac70..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-#![feature(rustc_private)]
-
-#![allow(private_in_public)]
-#![deny(improper_ctypes)]
-
-extern crate libc;
-
-use std::default::Default;
-use std::marker::PhantomData;
-
-trait Mirror { type It: ?Sized; }
-
-impl<T: ?Sized> Mirror for T { type It = Self; }
-
-#[repr(C)]
-pub struct StructWithProjection(*mut <StructWithProjection as Mirror>::It);
-
-#[repr(C)]
-pub struct StructWithProjectionAndLifetime<'a>(
-    &'a mut <StructWithProjectionAndLifetime<'a> as Mirror>::It
-);
-
-pub type I32Pair = (i32, i32);
-
-#[repr(C)]
-pub struct ZeroSize;
-
-pub type RustFn = fn();
-
-pub type RustBadRet = extern fn() -> Box<u32>;
-
-pub type CVoidRet = ();
-
-pub struct Foo;
-
-#[repr(transparent)]
-pub struct TransparentI128(i128);
-
-#[repr(transparent)]
-pub struct TransparentStr(&'static str);
-
-#[repr(transparent)]
-pub struct TransparentBadFn(RustBadRet);
-
-#[repr(transparent)]
-pub struct TransparentInt(u32);
-
-#[repr(transparent)]
-pub struct TransparentRef<'a>(&'a TransparentInt);
-
-#[repr(transparent)]
-pub struct TransparentLifetime<'a>(*const u8, PhantomData<&'a ()>);
-
-#[repr(transparent)]
-pub struct TransparentUnit<U>(f32, PhantomData<U>);
-
-#[repr(transparent)]
-pub struct TransparentCustomZst(i32, ZeroSize);
-
-#[repr(C)]
-pub struct ZeroSizeWithPhantomData(PhantomData<i32>);
-
-pub extern "C" fn ptr_type1(size: *const Foo) { }
-//~^ ERROR: uses type `Foo`
-
-pub extern "C" fn ptr_type2(size: *const Foo) { }
-//~^ ERROR: uses type `Foo`
-
-pub extern "C" fn slice_type(p: &[u32]) { }
-//~^ ERROR: uses type `[u32]`
-
-pub extern "C" fn str_type(p: &str) { }
-//~^ ERROR: uses type `str`
-
-pub extern "C" fn box_type(p: Box<u32>) { }
-//~^ ERROR uses type `std::boxed::Box<u32>`
-
-pub extern "C" fn char_type(p: char) { }
-//~^ ERROR uses type `char`
-
-pub extern "C" fn i128_type(p: i128) { }
-//~^ ERROR uses type `i128`
-
-pub extern "C" fn u128_type(p: u128) { }
-//~^ ERROR uses type `u128`
-
-pub extern "C" fn tuple_type(p: (i32, i32)) { }
-//~^ ERROR uses type `(i32, i32)`
-
-pub extern "C" fn tuple_type2(p: I32Pair) { }
-//~^ ERROR uses type `(i32, i32)`
-
-pub extern "C" fn zero_size(p: ZeroSize) { }
-//~^ ERROR uses type `ZeroSize`
-
-pub extern "C" fn zero_size_phantom(p: ZeroSizeWithPhantomData) { }
-//~^ ERROR uses type `ZeroSizeWithPhantomData`
-
-pub extern "C" fn zero_size_phantom_toplevel() -> PhantomData<bool> {
-//~^ ERROR uses type `std::marker::PhantomData<bool>`
-    Default::default()
-}
-
-pub extern "C" fn fn_type(p: RustFn) { }
-//~^ ERROR uses type `fn()`
-
-pub extern "C" fn fn_type2(p: fn()) { }
-//~^ ERROR uses type `fn()`
-
-pub extern "C" fn fn_contained(p: RustBadRet) { }
-//~^ ERROR: uses type `std::boxed::Box<u32>`
-
-pub extern "C" fn transparent_i128(p: TransparentI128) { }
-//~^ ERROR: uses type `i128`
-
-pub extern "C" fn transparent_str(p: TransparentStr) { }
-//~^ ERROR: uses type `str`
-
-pub extern "C" fn transparent_fn(p: TransparentBadFn) { }
-//~^ ERROR: uses type `std::boxed::Box<u32>`
-
-pub extern "C" fn good3(fptr: Option<extern fn()>) { }
-
-pub extern "C" fn good4(aptr: &[u8; 4 as usize]) { }
-
-pub extern "C" fn good5(s: StructWithProjection) { }
-
-pub extern "C" fn good6(s: StructWithProjectionAndLifetime) { }
-
-pub extern "C" fn good7(fptr: extern fn() -> ()) { }
-
-pub extern "C" fn good8(fptr: extern fn() -> !) { }
-
-pub extern "C" fn good9() -> () { }
-
-pub extern "C" fn good10() -> CVoidRet { }
-
-pub extern "C" fn good11(size: isize) { }
-
-pub extern "C" fn good12(size: usize) { }
-
-pub extern "C" fn good13(n: TransparentInt) { }
-
-pub extern "C" fn good14(p: TransparentRef) { }
-
-pub extern "C" fn good15(p: TransparentLifetime) { }
-
-pub extern "C" fn good16(p: TransparentUnit<ZeroSize>) { }
-
-pub extern "C" fn good17(p: TransparentCustomZst) { }
-
-#[allow(improper_ctypes)]
-pub extern "C" fn good18(_: &String) { }
-
-#[cfg(not(target_arch = "wasm32"))]
-pub extern "C" fn good1(size: *const libc::c_int) { }
-
-#[cfg(not(target_arch = "wasm32"))]
-pub extern "C" fn good2(size: *const libc::c_uint) { }
-
-pub extern "C" fn unused_generic1<T>(size: *const Foo) { }
-//~^ ERROR: uses type `Foo`
-
-pub extern "C" fn unused_generic2<T>() -> PhantomData<bool> {
-//~^ ERROR uses type `std::marker::PhantomData<bool>`
-    Default::default()
-}
-
-pub extern "C" fn used_generic1<T>(x: T) { }
-
-pub extern "C" fn used_generic2<T>(x: T, size: *const Foo) { }
-//~^ ERROR: uses type `Foo`
-
-pub extern "C" fn used_generic3<T: Default>() -> T {
-    Default::default()
-}
-
-pub extern "C" fn used_generic4<T>(x: Vec<T>) { }
-//~^ ERROR: uses type `std::vec::Vec<T>`
-
-pub extern "C" fn used_generic5<T>() -> Vec<T> {
-//~^ ERROR: uses type `std::vec::Vec<T>`
-    Default::default()
-}
-
-fn main() {}
diff --git a/src/test/ui/lint/lint-ctypes-fn.stderr b/src/test/ui/lint/lint-ctypes-fn.stderr
deleted file mode 100644 (file)
index 59bd6bf..0000000
+++ /dev/null
@@ -1,247 +0,0 @@
-error: `extern` fn uses type `Foo`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:63:35
-   |
-LL | pub extern "C" fn ptr_type1(size: *const Foo) { }
-   |                                   ^^^^^^^^^^ not FFI-safe
-   |
-note: lint level defined here
-  --> $DIR/lint-ctypes-fn.rs:4:9
-   |
-LL | #![deny(improper_ctypes)]
-   |         ^^^^^^^^^^^^^^^
-   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
-   = note: this struct has unspecified layout
-note: type defined here
-  --> $DIR/lint-ctypes-fn.rs:34:1
-   |
-LL | pub struct Foo;
-   | ^^^^^^^^^^^^^^^
-
-error: `extern` fn uses type `Foo`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:66:35
-   |
-LL | pub extern "C" fn ptr_type2(size: *const Foo) { }
-   |                                   ^^^^^^^^^^ not FFI-safe
-   |
-   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
-   = note: this struct has unspecified layout
-note: type defined here
-  --> $DIR/lint-ctypes-fn.rs:34:1
-   |
-LL | pub struct Foo;
-   | ^^^^^^^^^^^^^^^
-
-error: `extern` fn uses type `[u32]`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:69:33
-   |
-LL | pub extern "C" fn slice_type(p: &[u32]) { }
-   |                                 ^^^^^^ not FFI-safe
-   |
-   = help: consider using a raw pointer instead
-   = note: slices have no C equivalent
-
-error: `extern` fn uses type `str`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:72:31
-   |
-LL | pub extern "C" fn str_type(p: &str) { }
-   |                               ^^^^ not FFI-safe
-   |
-   = help: consider using `*const u8` and a length instead
-   = note: string slices have no C equivalent
-
-error: `extern` fn uses type `std::boxed::Box<u32>`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:75:31
-   |
-LL | pub extern "C" fn box_type(p: Box<u32>) { }
-   |                               ^^^^^^^^ not FFI-safe
-   |
-   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
-   = note: this struct has unspecified layout
-
-error: `extern` fn uses type `char`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:78:32
-   |
-LL | pub extern "C" fn char_type(p: char) { }
-   |                                ^^^^ not FFI-safe
-   |
-   = help: consider using `u32` or `libc::wchar_t` instead
-   = note: the `char` type has no C equivalent
-
-error: `extern` fn uses type `i128`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:81:32
-   |
-LL | pub extern "C" fn i128_type(p: i128) { }
-   |                                ^^^^ not FFI-safe
-   |
-   = note: 128-bit integers don't currently have a known stable ABI
-
-error: `extern` fn uses type `u128`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:84:32
-   |
-LL | pub extern "C" fn u128_type(p: u128) { }
-   |                                ^^^^ not FFI-safe
-   |
-   = note: 128-bit integers don't currently have a known stable ABI
-
-error: `extern` fn uses type `(i32, i32)`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:87:33
-   |
-LL | pub extern "C" fn tuple_type(p: (i32, i32)) { }
-   |                                 ^^^^^^^^^^ not FFI-safe
-   |
-   = help: consider using a struct instead
-   = note: tuples have unspecified layout
-
-error: `extern` fn uses type `(i32, i32)`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:90:34
-   |
-LL | pub extern "C" fn tuple_type2(p: I32Pair) { }
-   |                                  ^^^^^^^ not FFI-safe
-   |
-   = help: consider using a struct instead
-   = note: tuples have unspecified layout
-
-error: `extern` fn uses type `ZeroSize`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:93:32
-   |
-LL | pub extern "C" fn zero_size(p: ZeroSize) { }
-   |                                ^^^^^^^^ not FFI-safe
-   |
-   = help: consider adding a member to this struct
-   = note: this struct has no fields
-note: type defined here
-  --> $DIR/lint-ctypes-fn.rs:26:1
-   |
-LL | pub struct ZeroSize;
-   | ^^^^^^^^^^^^^^^^^^^^
-
-error: `extern` fn uses type `ZeroSizeWithPhantomData`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:96:40
-   |
-LL | pub extern "C" fn zero_size_phantom(p: ZeroSizeWithPhantomData) { }
-   |                                        ^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
-   |
-   = note: composed only of `PhantomData`
-note: type defined here
-  --> $DIR/lint-ctypes-fn.rs:61:1
-   |
-LL | pub struct ZeroSizeWithPhantomData(PhantomData<i32>);
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: `extern` fn uses type `std::marker::PhantomData<bool>`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:99:51
-   |
-LL | pub extern "C" fn zero_size_phantom_toplevel() -> PhantomData<bool> {
-   |                                                   ^^^^^^^^^^^^^^^^^ not FFI-safe
-   |
-   = note: composed only of `PhantomData`
-
-error: `extern` fn uses type `fn()`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:104:30
-   |
-LL | pub extern "C" fn fn_type(p: RustFn) { }
-   |                              ^^^^^^ not FFI-safe
-   |
-   = help: consider using an `extern fn(...) -> ...` function pointer instead
-   = note: this function pointer has Rust-specific calling convention
-
-error: `extern` fn uses type `fn()`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:107:31
-   |
-LL | pub extern "C" fn fn_type2(p: fn()) { }
-   |                               ^^^^ not FFI-safe
-   |
-   = help: consider using an `extern fn(...) -> ...` function pointer instead
-   = note: this function pointer has Rust-specific calling convention
-
-error: `extern` fn uses type `std::boxed::Box<u32>`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:110:35
-   |
-LL | pub extern "C" fn fn_contained(p: RustBadRet) { }
-   |                                   ^^^^^^^^^^ not FFI-safe
-   |
-   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
-   = note: this struct has unspecified layout
-
-error: `extern` fn uses type `i128`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:113:39
-   |
-LL | pub extern "C" fn transparent_i128(p: TransparentI128) { }
-   |                                       ^^^^^^^^^^^^^^^ not FFI-safe
-   |
-   = note: 128-bit integers don't currently have a known stable ABI
-
-error: `extern` fn uses type `str`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:116:38
-   |
-LL | pub extern "C" fn transparent_str(p: TransparentStr) { }
-   |                                      ^^^^^^^^^^^^^^ not FFI-safe
-   |
-   = help: consider using `*const u8` and a length instead
-   = note: string slices have no C equivalent
-
-error: `extern` fn uses type `std::boxed::Box<u32>`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:119:37
-   |
-LL | pub extern "C" fn transparent_fn(p: TransparentBadFn) { }
-   |                                     ^^^^^^^^^^^^^^^^ not FFI-safe
-   |
-   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
-   = note: this struct has unspecified layout
-
-error: `extern` fn uses type `Foo`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:161:44
-   |
-LL | pub extern "C" fn unused_generic1<T>(size: *const Foo) { }
-   |                                            ^^^^^^^^^^ not FFI-safe
-   |
-   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
-   = note: this struct has unspecified layout
-note: type defined here
-  --> $DIR/lint-ctypes-fn.rs:34:1
-   |
-LL | pub struct Foo;
-   | ^^^^^^^^^^^^^^^
-
-error: `extern` fn uses type `std::marker::PhantomData<bool>`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:164:43
-   |
-LL | pub extern "C" fn unused_generic2<T>() -> PhantomData<bool> {
-   |                                           ^^^^^^^^^^^^^^^^^ not FFI-safe
-   |
-   = note: composed only of `PhantomData`
-
-error: `extern` fn uses type `Foo`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:171:48
-   |
-LL | pub extern "C" fn used_generic2<T>(x: T, size: *const Foo) { }
-   |                                                ^^^^^^^^^^ not FFI-safe
-   |
-   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
-   = note: this struct has unspecified layout
-note: type defined here
-  --> $DIR/lint-ctypes-fn.rs:34:1
-   |
-LL | pub struct Foo;
-   | ^^^^^^^^^^^^^^^
-
-error: `extern` fn uses type `std::vec::Vec<T>`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:178:39
-   |
-LL | pub extern "C" fn used_generic4<T>(x: Vec<T>) { }
-   |                                       ^^^^^^ not FFI-safe
-   |
-   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
-   = note: this struct has unspecified layout
-
-error: `extern` fn uses type `std::vec::Vec<T>`, which is not FFI-safe
-  --> $DIR/lint-ctypes-fn.rs:181:41
-   |
-LL | pub extern "C" fn used_generic5<T>() -> Vec<T> {
-   |                                         ^^^^^^ not FFI-safe
-   |
-   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
-   = note: this struct has unspecified layout
-
-error: aborting due to 24 previous errors
-
index 6b37ac3704038dacb876798ca3dcf0df4d6c37cf..69fd64c1c092c262e52dfa631a3889d9036fdaef 100644 (file)
@@ -1,10 +1,8 @@
 // run-pass
-#[allow(improper_ctypes)]
 pub extern "C" fn tuple2() -> (u16, u8) {
     (1, 2)
 }
 
-#[allow(improper_ctypes)]
 pub extern "C" fn tuple3() -> (u8, u8, u8) {
     (1, 2, 3)
 }
index c45629eddff01f331ae4d71e95b67f9e4862772f..fc0db03e3a96894350a9611f398c150de1afebe3 100644 (file)
@@ -74,7 +74,6 @@ fn test8() -> isize {
     Two::two()
 }
 
-#[allow(improper_ctypes)]
 extern fn simple_extern(x: u32, y: (u32, u32)) -> u32 {
     x + y.0 * y.1
 }