Skip to content

Remove i128 and u128 from improper_ctypes_definitions #137306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
@@ -372,8 +372,6 @@ lint_improper_ctypes = `extern` {$desc} uses type `{$ty}`, which is not FFI-safe
.label = not FFI-safe
.note = the type is defined here
lint_improper_ctypes_128bit = 128-bit integers don't currently have a known stable ABI
lint_improper_ctypes_array_help = consider passing a pointer to the array
lint_improper_ctypes_array_reason = passing raw arrays by value is not FFI-safe
16 changes: 1 addition & 15 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::iter;
use std::ops::ControlFlow;

use rustc_abi::{
BackendRepr, Integer, IntegerType, TagEncoding, VariantIdx, Variants, WrappingRange,
};
use rustc_abi::{BackendRepr, TagEncoding, VariantIdx, Variants, WrappingRange};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::DiagMessage;
use rustc_hir::intravisit::VisitorExt;
@@ -1274,14 +1272,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
};
}

if let Some(IntegerType::Fixed(Integer::I128, _)) = def.repr().int {
return FfiUnsafe {
ty,
reason: fluent::lint_improper_ctypes_128bit,
help: None,
};
}

use improper_ctypes::check_non_exhaustive_variant;

let non_exhaustive = def.variant_list_has_applicable_non_exhaustive();
@@ -1314,10 +1304,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
// but only the base type is relevant for being representable in FFI.
ty::Pat(base, ..) => self.check_type_for_ffi(acc, base),

ty::Int(ty::IntTy::I128) | ty::Uint(ty::UintTy::U128) => {
FfiUnsafe { ty, reason: fluent::lint_improper_ctypes_128bit, help: None }
}

// Primitive types with a stable representation.
ty::Bool | ty::Int(..) | ty::Uint(..) | ty::Float(..) | ty::Never => FfiSafe,

14 changes: 14 additions & 0 deletions library/core/src/primitive_docs.rs
Original file line number Diff line number Diff line change
@@ -1428,6 +1428,18 @@ mod prim_i64 {}
#[rustc_doc_primitive = "i128"]
//
/// The 128-bit signed integer type.
///
/// # ABI compatibility
///
/// Rust's `i128` is expected to be ABI-compatible with C's `__int128` on platforms where the type
/// is available, which includes most 64-bit architectures. If any platforms that do not specify
/// `__int128` are updated to introduce it, the Rust `i128` ABI on relevant targets will be changed
/// to match.
///
/// It is important to note that in C, `__int128` is _not_ the same as `_BitInt(128)`, and the two
/// types are allowed to have different ABIs. In particular, on x86, `__int128` and `_BitInt(128)`
/// do not use the same alignment. `i128` is intended to always match `__int128` and does not
/// attempt to match `_BitInt(128)` on platforms without `__int128`.
#[stable(feature = "i128", since = "1.26.0")]
mod prim_i128 {}

@@ -1458,6 +1470,8 @@ mod prim_u64 {}
#[rustc_doc_primitive = "u128"]
//
/// The 128-bit unsigned integer type.
///
/// Please see [the documentation for `i128`](prim@i128) for information on ABI compatibility.
#[stable(feature = "i128", since = "1.26.0")]
mod prim_u128 {}

1 change: 0 additions & 1 deletion tests/ui/asm/naked-functions-ffi.rs
Original file line number Diff line number Diff line change
@@ -7,6 +7,5 @@ use std::arch::naked_asm;
#[unsafe(naked)]
pub extern "C" fn naked(p: char) -> u128 {
//~^ WARN uses type `char`
//~| WARN uses type `u128`
naked_asm!("")
}
10 changes: 1 addition & 9 deletions tests/ui/asm/naked-functions-ffi.stderr
Original file line number Diff line number Diff line change
@@ -8,13 +8,5 @@ LL | pub extern "C" fn naked(p: char) -> u128 {
= note: the `char` type has no C equivalent
= note: `#[warn(improper_ctypes_definitions)]` on by default

warning: `extern` fn uses type `u128`, which is not FFI-safe
--> $DIR/naked-functions-ffi.rs:8:37
|
LL | pub extern "C" fn naked(p: char) -> u128 {
| ^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI

warning: 2 warnings emitted
warning: 1 warning emitted

10 changes: 2 additions & 8 deletions tests/ui/lint/lint-ctypes-enum.rs
Original file line number Diff line number Diff line change
@@ -87,8 +87,8 @@ extern "C" {
fn repr_c(x: ReprC);
fn repr_u8(x: U8);
fn repr_isize(x: Isize);
fn repr_u128(x: U128); //~ ERROR `extern` block uses type `U128`
fn repr_i128(x: I128); //~ ERROR `extern` block uses type `I128`
fn repr_u128(x: U128);
fn repr_i128(x: I128);
fn option_ref(x: Option<&'static u8>);
fn option_fn(x: Option<extern "C" fn()>);
fn option_nonnull(x: Option<std::ptr::NonNull<u8>>);
@@ -98,14 +98,12 @@ extern "C" {
fn option_nonzero_u32(x: Option<num::NonZero<u32>>);
fn option_nonzero_u64(x: Option<num::NonZero<u64>>);
fn option_nonzero_u128(x: Option<num::NonZero<u128>>);
//~^ ERROR `extern` block uses type `u128`
fn option_nonzero_usize(x: Option<num::NonZero<usize>>);
fn option_nonzero_i8(x: Option<num::NonZero<i8>>);
fn option_nonzero_i16(x: Option<num::NonZero<i16>>);
fn option_nonzero_i32(x: Option<num::NonZero<i32>>);
fn option_nonzero_i64(x: Option<num::NonZero<i64>>);
fn option_nonzero_i128(x: Option<num::NonZero<i128>>);
//~^ ERROR `extern` block uses type `i128`
fn option_nonzero_isize(x: Option<num::NonZero<isize>>);
fn option_transparent_struct(x: Option<TransparentStruct<num::NonZero<u8>>>);
fn option_transparent_enum(x: Option<TransparentEnum<num::NonZero<u8>>>);
@@ -123,14 +121,12 @@ extern "C" {
fn result_nonzero_u32_t(x: Result<num::NonZero<u32>, ()>);
fn result_nonzero_u64_t(x: Result<num::NonZero<u64>, ()>);
fn result_nonzero_u128_t(x: Result<num::NonZero<u128>, ()>);
//~^ ERROR `extern` block uses type `u128`
fn result_nonzero_usize_t(x: Result<num::NonZero<usize>, ()>);
fn result_nonzero_i8_t(x: Result<num::NonZero<i8>, ()>);
fn result_nonzero_i16_t(x: Result<num::NonZero<i16>, ()>);
fn result_nonzero_i32_t(x: Result<num::NonZero<i32>, ()>);
fn result_nonzero_i64_t(x: Result<num::NonZero<i64>, ()>);
fn result_nonzero_i128_t(x: Result<num::NonZero<i128>, ()>);
//~^ ERROR `extern` block uses type `i128`
fn result_nonzero_isize_t(x: Result<num::NonZero<isize>, ()>);
fn result_transparent_struct_t(x: Result<TransparentStruct<num::NonZero<u8>>, ()>);
fn result_transparent_enum_t(x: Result<TransparentEnum<num::NonZero<u8>>, ()>);
@@ -161,14 +157,12 @@ extern "C" {
fn result_nonzero_u32_e(x: Result<(), num::NonZero<u32>>);
fn result_nonzero_u64_e(x: Result<(), num::NonZero<u64>>);
fn result_nonzero_u128_e(x: Result<(), num::NonZero<u128>>);
//~^ ERROR `extern` block uses type `u128`
fn result_nonzero_usize_e(x: Result<(), num::NonZero<usize>>);
fn result_nonzero_i8_e(x: Result<(), num::NonZero<i8>>);
fn result_nonzero_i16_e(x: Result<(), num::NonZero<i16>>);
fn result_nonzero_i32_e(x: Result<(), num::NonZero<i32>>);
fn result_nonzero_i64_e(x: Result<(), num::NonZero<i64>>);
fn result_nonzero_i128_e(x: Result<(), num::NonZero<i128>>);
//~^ ERROR `extern` block uses type `i128`
fn result_nonzero_isize_e(x: Result<(), num::NonZero<isize>>);
fn result_transparent_struct_e(x: Result<(), TransparentStruct<num::NonZero<u8>>>);
fn result_transparent_enum_e(x: Result<(), TransparentEnum<num::NonZero<u8>>>);
112 changes: 19 additions & 93 deletions tests/ui/lint/lint-ctypes-enum.stderr
Original file line number Diff line number Diff line change
@@ -45,50 +45,8 @@ note: the type is defined here
LL | enum T {
| ^^^^^^

error: `extern` block uses type `U128`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:90:21
|
LL | fn repr_u128(x: U128);
| ^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI
note: the type is defined here
--> $DIR/lint-ctypes-enum.rs:46:1
|
LL | enum U128 {
| ^^^^^^^^^

error: `extern` block uses type `I128`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:91:21
|
LL | fn repr_i128(x: I128);
| ^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI
note: the type is defined here
--> $DIR/lint-ctypes-enum.rs:53:1
|
LL | enum I128 {
| ^^^^^^^^^

error: `extern` block uses type `u128`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:100:31
|
LL | fn option_nonzero_u128(x: Option<num::NonZero<u128>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI

error: `extern` block uses type `i128`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:107:31
|
LL | fn option_nonzero_i128(x: Option<num::NonZero<i128>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI

error: `extern` block uses type `Option<TransparentUnion<NonZero<u8>>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:112:36
--> $DIR/lint-ctypes-enum.rs:110:36
|
LL | fn option_transparent_union(x: Option<TransparentUnion<num::NonZero<u8>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -97,7 +55,7 @@ LL | fn option_transparent_union(x: Option<TransparentUnion<num::NonZero<u8>
= note: enum has no representation hint

error: `extern` block uses type `Option<Rust<NonZero<u8>>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:114:28
--> $DIR/lint-ctypes-enum.rs:112:28
|
LL | fn option_repr_rust(x: Option<Rust<num::NonZero<u8>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -106,32 +64,16 @@ LL | fn option_repr_rust(x: Option<Rust<num::NonZero<u8>>>);
= note: enum has no representation hint

error: `extern` block uses type `Option<u8>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:115:21
--> $DIR/lint-ctypes-enum.rs:113:21
|
LL | fn option_u8(x: Option<u8>);
| ^^^^^^^^^^ not FFI-safe
|
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint

error: `extern` block uses type `u128`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:125:33
|
LL | fn result_nonzero_u128_t(x: Result<num::NonZero<u128>, ()>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI

error: `extern` block uses type `i128`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:132:33
|
LL | fn result_nonzero_i128_t(x: Result<num::NonZero<i128>, ()>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI

error: `extern` block uses type `Result<TransparentUnion<NonZero<u8>>, ()>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:137:38
--> $DIR/lint-ctypes-enum.rs:133:38
|
LL | fn result_transparent_union_t(x: Result<TransparentUnion<num::NonZero<u8>>, ()>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -140,7 +82,7 @@ LL | fn result_transparent_union_t(x: Result<TransparentUnion<num::NonZero<u
= note: enum has no representation hint

error: `extern` block uses type `Result<Rust<NonZero<u8>>, ()>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:139:30
--> $DIR/lint-ctypes-enum.rs:135:30
|
LL | fn result_repr_rust_t(x: Result<Rust<num::NonZero<u8>>, ()>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -149,7 +91,7 @@ LL | fn result_repr_rust_t(x: Result<Rust<num::NonZero<u8>>, ()>);
= note: enum has no representation hint

error: `extern` block uses type `Result<NonZero<u8>, U>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:143:51
--> $DIR/lint-ctypes-enum.rs:139:51
|
LL | fn result_1zst_exhaustive_single_variant_t(x: Result<num::NonZero<u8>, U>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -158,7 +100,7 @@ LL | fn result_1zst_exhaustive_single_variant_t(x: Result<num::NonZero<u8>,
= note: enum has no representation hint

error: `extern` block uses type `Result<NonZero<u8>, B>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:145:53
--> $DIR/lint-ctypes-enum.rs:141:53
|
LL | fn result_1zst_exhaustive_multiple_variant_t(x: Result<num::NonZero<u8>, B>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -167,7 +109,7 @@ LL | fn result_1zst_exhaustive_multiple_variant_t(x: Result<num::NonZero<u8>
= note: enum has no representation hint

error: `extern` block uses type `Result<NonZero<u8>, NonExhaustive>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:147:51
--> $DIR/lint-ctypes-enum.rs:143:51
|
LL | fn result_1zst_non_exhaustive_no_variant_t(x: Result<num::NonZero<u8>, NonExhaustive>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -176,7 +118,7 @@ LL | fn result_1zst_non_exhaustive_no_variant_t(x: Result<num::NonZero<u8>,
= note: enum has no representation hint

error: `extern` block uses type `Result<NonZero<u8>, Field>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:150:49
--> $DIR/lint-ctypes-enum.rs:146:49
|
LL | fn result_1zst_exhaustive_single_field_t(x: Result<num::NonZero<u8>, Field>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -185,32 +127,16 @@ LL | fn result_1zst_exhaustive_single_field_t(x: Result<num::NonZero<u8>, Fi
= note: enum has no representation hint

error: `extern` block uses type `Result<Result<(), NonZero<u8>>, ()>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:152:30
--> $DIR/lint-ctypes-enum.rs:148:30
|
LL | fn result_cascading_t(x: Result<Result<(), num::NonZero<u8>>, ()>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint

error: `extern` block uses type `u128`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:163:33
|
LL | fn result_nonzero_u128_e(x: Result<(), num::NonZero<u128>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI

error: `extern` block uses type `i128`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:170:33
|
LL | fn result_nonzero_i128_e(x: Result<(), num::NonZero<i128>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI

error: `extern` block uses type `Result<(), TransparentUnion<NonZero<u8>>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:175:38
--> $DIR/lint-ctypes-enum.rs:169:38
|
LL | fn result_transparent_union_e(x: Result<(), TransparentUnion<num::NonZero<u8>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -219,7 +145,7 @@ LL | fn result_transparent_union_e(x: Result<(), TransparentUnion<num::NonZe
= note: enum has no representation hint

error: `extern` block uses type `Result<(), Rust<NonZero<u8>>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:177:30
--> $DIR/lint-ctypes-enum.rs:171:30
|
LL | fn result_repr_rust_e(x: Result<(), Rust<num::NonZero<u8>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -228,7 +154,7 @@ LL | fn result_repr_rust_e(x: Result<(), Rust<num::NonZero<u8>>>);
= note: enum has no representation hint

error: `extern` block uses type `Result<U, NonZero<u8>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:181:51
--> $DIR/lint-ctypes-enum.rs:175:51
|
LL | fn result_1zst_exhaustive_single_variant_e(x: Result<U, num::NonZero<u8>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -237,7 +163,7 @@ LL | fn result_1zst_exhaustive_single_variant_e(x: Result<U, num::NonZero<u8
= note: enum has no representation hint

error: `extern` block uses type `Result<B, NonZero<u8>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:183:53
--> $DIR/lint-ctypes-enum.rs:177:53
|
LL | fn result_1zst_exhaustive_multiple_variant_e(x: Result<B, num::NonZero<u8>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -246,7 +172,7 @@ LL | fn result_1zst_exhaustive_multiple_variant_e(x: Result<B, num::NonZero<
= note: enum has no representation hint

error: `extern` block uses type `Result<NonExhaustive, NonZero<u8>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:185:51
--> $DIR/lint-ctypes-enum.rs:179:51
|
LL | fn result_1zst_non_exhaustive_no_variant_e(x: Result<NonExhaustive, num::NonZero<u8>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -255,7 +181,7 @@ LL | fn result_1zst_non_exhaustive_no_variant_e(x: Result<NonExhaustive, num
= note: enum has no representation hint

error: `extern` block uses type `Result<Field, NonZero<u8>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:188:49
--> $DIR/lint-ctypes-enum.rs:182:49
|
LL | fn result_1zst_exhaustive_single_field_e(x: Result<Field, num::NonZero<u8>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -264,7 +190,7 @@ LL | fn result_1zst_exhaustive_single_field_e(x: Result<Field, num::NonZero<
= note: enum has no representation hint

error: `extern` block uses type `Result<(), Result<(), NonZero<u8>>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:190:30
--> $DIR/lint-ctypes-enum.rs:184:30
|
LL | fn result_cascading_e(x: Result<(), Result<(), num::NonZero<u8>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -273,13 +199,13 @@ LL | fn result_cascading_e(x: Result<(), Result<(), num::NonZero<u8>>>);
= note: enum has no representation hint

error: `extern` block uses type `Result<(), ()>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:192:27
--> $DIR/lint-ctypes-enum.rs:186:27
|
LL | fn result_unit_t_e(x: Result<(), ()>);
| ^^^^^^^^^^^^^^ not FFI-safe
|
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint

error: aborting due to 29 previous errors
error: aborting due to 21 previous errors

15 changes: 6 additions & 9 deletions tests/ui/lint/lint-ctypes-fn.rs
Original file line number Diff line number Diff line change
@@ -89,12 +89,6 @@ pub extern "C" fn boxed_trait(p: Box<dyn Trait>) { }
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)`

@@ -120,9 +114,6 @@ pub extern "C" fn fn_type2(p: fn()) { }

pub extern "C" fn fn_contained(p: RustBadRet) { }

pub extern "C" fn transparent_i128(p: TransparentI128) { }
//~^ ERROR: uses type `i128`

pub extern "C" fn transparent_str(p: TransparentStr) { }
//~^ ERROR: uses type `str`

@@ -161,6 +152,12 @@ pub extern "C" fn good17(p: TransparentCustomZst) { }
#[allow(improper_ctypes_definitions)]
pub extern "C" fn good18(_: &String) { }

pub extern "C" fn good_i128_type(p: i128) { }

pub extern "C" fn good_u128_type(p: u128) { }

pub extern "C" fn good_transparent_i128(p: TransparentI128) { }

#[cfg(not(target_arch = "wasm32"))]
pub extern "C" fn good1(size: *const c_int) { }

48 changes: 12 additions & 36 deletions tests/ui/lint/lint-ctypes-fn.stderr
Original file line number Diff line number Diff line change
@@ -54,24 +54,8 @@ LL | pub extern "C" fn char_type(p: char) { }
= 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:92: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:95: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:98:33
--> $DIR/lint-ctypes-fn.rs:92:33
|
LL | pub extern "C" fn tuple_type(p: (i32, i32)) { }
| ^^^^^^^^^^ not FFI-safe
@@ -80,7 +64,7 @@ LL | pub extern "C" fn tuple_type(p: (i32, i32)) { }
= note: tuples have unspecified layout

error: `extern` fn uses type `(i32, i32)`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:101:34
--> $DIR/lint-ctypes-fn.rs:95:34
|
LL | pub extern "C" fn tuple_type2(p: I32Pair) { }
| ^^^^^^^ not FFI-safe
@@ -89,7 +73,7 @@ LL | pub extern "C" fn tuple_type2(p: I32Pair) { }
= note: tuples have unspecified layout

error: `extern` fn uses type `ZeroSize`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:104:32
--> $DIR/lint-ctypes-fn.rs:98:32
|
LL | pub extern "C" fn zero_size(p: ZeroSize) { }
| ^^^^^^^^ not FFI-safe
@@ -103,7 +87,7 @@ LL | pub struct ZeroSize;
| ^^^^^^^^^^^^^^^^^^^

error: `extern` fn uses type `ZeroSizeWithPhantomData`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:107:40
--> $DIR/lint-ctypes-fn.rs:101:40
|
LL | pub extern "C" fn zero_size_phantom(p: ZeroSizeWithPhantomData) { }
| ^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -116,15 +100,15 @@ LL | pub struct ZeroSizeWithPhantomData(PhantomData<i32>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: `extern` fn uses type `PhantomData<bool>`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:110:51
--> $DIR/lint-ctypes-fn.rs:104: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:115:30
--> $DIR/lint-ctypes-fn.rs:109:30
|
LL | pub extern "C" fn fn_type(p: RustFn) { }
| ^^^^^^ not FFI-safe
@@ -133,24 +117,16 @@ LL | pub extern "C" fn fn_type(p: RustFn) { }
= 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:118:31
--> $DIR/lint-ctypes-fn.rs:112: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 `i128`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:123: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:126:38
--> $DIR/lint-ctypes-fn.rs:117:38
|
LL | pub extern "C" fn transparent_str(p: TransparentStr) { }
| ^^^^^^^^^^^^^^ not FFI-safe
@@ -159,15 +135,15 @@ LL | pub extern "C" fn transparent_str(p: TransparentStr) { }
= note: string slices have no C equivalent

error: `extern` fn uses type `PhantomData<bool>`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:172:43
--> $DIR/lint-ctypes-fn.rs:169:43
|
LL | pub extern "C" fn unused_generic2<T>() -> PhantomData<bool> {
| ^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: composed only of `PhantomData`

error: `extern` fn uses type `Vec<T>`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:185:39
--> $DIR/lint-ctypes-fn.rs:182:39
|
LL | pub extern "C" fn used_generic4<T>(x: Vec<T>) { }
| ^^^^^^ not FFI-safe
@@ -176,13 +152,13 @@ LL | pub extern "C" fn used_generic4<T>(x: Vec<T>) { }
= note: this struct has unspecified layout

error: `extern` fn uses type `Vec<T>`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:188:41
--> $DIR/lint-ctypes-fn.rs:185: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 20 previous errors
error: aborting due to 17 previous errors

12 changes: 5 additions & 7 deletions tests/ui/lint/lint-ctypes.rs
Original file line number Diff line number Diff line change
@@ -54,8 +54,6 @@ extern "C" {
pub fn opt_box_type(p: Option<Box<u32>>);
//~^ ERROR uses type `Option<Box<u32>>`
pub fn char_type(p: char); //~ ERROR uses type `char`
pub fn i128_type(p: i128); //~ ERROR uses type `i128`
pub fn u128_type(p: u128); //~ ERROR uses type `u128`
pub fn trait_type(p: &dyn Bar); //~ ERROR uses type `dyn Bar`
pub fn tuple_type(p: (i32, i32)); //~ ERROR uses type `(i32, i32)`
pub fn tuple_type2(p: I32Pair); //~ ERROR uses type `(i32, i32)`
@@ -67,7 +65,6 @@ extern "C" {
pub fn fn_type(p: RustFn); //~ ERROR uses type `fn()`
pub fn fn_type2(p: fn()); //~ ERROR uses type `fn()`
pub fn fn_contained(p: RustBadRet); //~ ERROR: uses type `Box<u32>`
pub fn transparent_i128(p: TransparentI128); //~ ERROR: uses type `i128`
pub fn transparent_str(p: TransparentStr); //~ ERROR: uses type `str`
pub fn transparent_fn(p: TransparentBadFn); //~ ERROR: uses type `Box<u32>`
pub fn raw_array(arr: [u8; 8]); //~ ERROR: uses type `[u8; 8]`
@@ -77,9 +74,6 @@ extern "C" {
pub fn no_niche_b(b: Option<UnsafeCell<&i32>>);
//~^ ERROR: uses type `Option<UnsafeCell<&i32>>`

pub static static_u128_type: u128; //~ ERROR: uses type `u128`
pub static static_u128_array_type: [u128; 16]; //~ ERROR: uses type `u128`

pub fn good3(fptr: Option<extern "C" fn()>);
pub fn good4(aptr: &[u8; 4 as usize]);
pub fn good5(s: StructWithProjection);
@@ -99,7 +93,11 @@ extern "C" {
pub fn good18(_: &String);
pub fn good20(arr: *const [u8; 8]);
pub static good21: [u8; 8];

pub fn good_i128_type(p: i128);
pub fn good_u128_type(p: u128);
pub fn good_transparent_i128(p: TransparentI128);
pub static good_static_u128_type: u128;
pub static good_static_u128_array_type: [u128; 16];
}

#[allow(improper_ctypes)]
70 changes: 15 additions & 55 deletions tests/ui/lint/lint-ctypes.stderr
Original file line number Diff line number Diff line change
@@ -85,32 +85,16 @@ LL | pub fn char_type(p: char);
= help: consider using `u32` or `libc::wchar_t` instead
= note: the `char` type has no C equivalent

error: `extern` block uses type `i128`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:57:25
|
LL | pub fn i128_type(p: i128);
| ^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI

error: `extern` block uses type `u128`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:58:25
|
LL | pub fn u128_type(p: u128);
| ^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI

error: `extern` block uses type `dyn Bar`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:59:26
--> $DIR/lint-ctypes.rs:57:26
|
LL | pub fn trait_type(p: &dyn Bar);
| ^^^^^^^^ not FFI-safe
|
= note: trait objects have no C equivalent

error: `extern` block uses type `(i32, i32)`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:60:26
--> $DIR/lint-ctypes.rs:58:26
|
LL | pub fn tuple_type(p: (i32, i32));
| ^^^^^^^^^^ not FFI-safe
@@ -119,7 +103,7 @@ LL | pub fn tuple_type(p: (i32, i32));
= note: tuples have unspecified layout

error: `extern` block uses type `(i32, i32)`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:61:27
--> $DIR/lint-ctypes.rs:59:27
|
LL | pub fn tuple_type2(p: I32Pair);
| ^^^^^^^ not FFI-safe
@@ -128,7 +112,7 @@ LL | pub fn tuple_type2(p: I32Pair);
= note: tuples have unspecified layout

error: `extern` block uses type `ZeroSize`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:62:25
--> $DIR/lint-ctypes.rs:60:25
|
LL | pub fn zero_size(p: ZeroSize);
| ^^^^^^^^ not FFI-safe
@@ -142,7 +126,7 @@ LL | pub struct ZeroSize;
| ^^^^^^^^^^^^^^^^^^^

error: `extern` block uses type `ZeroSizeWithPhantomData`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:63:33
--> $DIR/lint-ctypes.rs:61:33
|
LL | pub fn zero_size_phantom(p: ZeroSizeWithPhantomData);
| ^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -155,15 +139,15 @@ LL | pub struct ZeroSizeWithPhantomData(::std::marker::PhantomData<i32>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: `extern` block uses type `PhantomData<bool>`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:66:12
--> $DIR/lint-ctypes.rs:64:12
|
LL | -> ::std::marker::PhantomData<bool>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: composed only of `PhantomData`

error: `extern` block uses type `fn()`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:67:23
--> $DIR/lint-ctypes.rs:65:23
|
LL | pub fn fn_type(p: RustFn);
| ^^^^^^ not FFI-safe
@@ -172,7 +156,7 @@ LL | pub fn fn_type(p: RustFn);
= note: this function pointer has Rust-specific calling convention

error: `extern` block uses type `fn()`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:68:24
--> $DIR/lint-ctypes.rs:66:24
|
LL | pub fn fn_type2(p: fn());
| ^^^^ not FFI-safe
@@ -181,24 +165,16 @@ LL | pub fn fn_type2(p: fn());
= note: this function pointer has Rust-specific calling convention

error: `extern` block uses type `Box<u32>`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:69:28
--> $DIR/lint-ctypes.rs:67:28
|
LL | pub 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` block uses type `i128`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:70:32
|
LL | pub fn transparent_i128(p: TransparentI128);
| ^^^^^^^^^^^^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI

error: `extern` block uses type `str`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:71:31
--> $DIR/lint-ctypes.rs:68:31
|
LL | pub fn transparent_str(p: TransparentStr);
| ^^^^^^^^^^^^^^ not FFI-safe
@@ -207,7 +183,7 @@ LL | pub fn transparent_str(p: TransparentStr);
= note: string slices have no C equivalent

error: `extern` block uses type `Box<u32>`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:72:30
--> $DIR/lint-ctypes.rs:69:30
|
LL | pub fn transparent_fn(p: TransparentBadFn);
| ^^^^^^^^^^^^^^^^ not FFI-safe
@@ -216,7 +192,7 @@ LL | pub fn transparent_fn(p: TransparentBadFn);
= note: this struct has unspecified layout

error: `extern` block uses type `[u8; 8]`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:73:27
--> $DIR/lint-ctypes.rs:70:27
|
LL | pub fn raw_array(arr: [u8; 8]);
| ^^^^^^^ not FFI-safe
@@ -225,7 +201,7 @@ LL | pub fn raw_array(arr: [u8; 8]);
= note: passing raw arrays by value is not FFI-safe

error: `extern` block uses type `Option<UnsafeCell<extern "C" fn()>>`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:75:26
--> $DIR/lint-ctypes.rs:72:26
|
LL | pub fn no_niche_a(a: Option<UnsafeCell<extern "C" fn()>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -234,29 +210,13 @@ LL | pub fn no_niche_a(a: Option<UnsafeCell<extern "C" fn()>>);
= note: enum has no representation hint

error: `extern` block uses type `Option<UnsafeCell<&i32>>`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:77:26
--> $DIR/lint-ctypes.rs:74:26
|
LL | pub fn no_niche_b(b: Option<UnsafeCell<&i32>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint

error: `extern` block uses type `u128`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:80:34
|
LL | pub static static_u128_type: u128;
| ^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI

error: `extern` block uses type `u128`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:81:40
|
LL | pub static static_u128_array_type: [u128; 16];
| ^^^^^^^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI

error: aborting due to 27 previous errors
error: aborting due to 22 previous errors