Skip to content
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

Remove i128 and u128 from improper_ctypes_definitions #137306

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Expand Up @@ -359,8 +359,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
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,10 +1296,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,

Expand Down
1 change: 0 additions & 1 deletion tests/ui/asm/naked-functions-ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::arch::naked_asm;
#[naked]
pub extern "C" fn naked(p: char) -> u128 {
//~^ WARN uses type `char`
//~| WARN uses type `u128`
unsafe {
naked_asm!("");
}
Expand Down
10 changes: 1 addition & 9 deletions tests/ui/asm/naked-functions-ffi.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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:9: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

6 changes: 0 additions & 6 deletions tests/ui/lint/lint-ctypes-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,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>>>);
Expand All @@ -105,14 +103,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>>, ()>);
Expand Down Expand Up @@ -143,14 +139,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>>>);
Expand Down
86 changes: 19 additions & 67 deletions tests/ui/lint/lint-ctypes-enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +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:82: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:89: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:94:36
--> $DIR/lint-ctypes-enum.rs:92:36
|
LL | fn option_transparent_union(x: Option<TransparentUnion<num::NonZero<u8>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -71,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:96:28
--> $DIR/lint-ctypes-enum.rs:94:28
|
LL | fn option_repr_rust(x: Option<Rust<num::NonZero<u8>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -80,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:97:21
--> $DIR/lint-ctypes-enum.rs:95: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:107: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:114: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:119:38
--> $DIR/lint-ctypes-enum.rs:115:38
|
LL | fn result_transparent_union_t(x: Result<TransparentUnion<num::NonZero<u8>>, ()>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -114,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:121:30
--> $DIR/lint-ctypes-enum.rs:117:30
|
LL | fn result_repr_rust_t(x: Result<Rust<num::NonZero<u8>>, ()>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -123,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:125:51
--> $DIR/lint-ctypes-enum.rs:121:51
|
LL | fn result_1zst_exhaustive_single_variant_t(x: Result<num::NonZero<u8>, U>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -132,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:127:53
--> $DIR/lint-ctypes-enum.rs:123:53
|
LL | fn result_1zst_exhaustive_multiple_variant_t(x: Result<num::NonZero<u8>, B>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -141,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:129:51
--> $DIR/lint-ctypes-enum.rs:125:51
|
LL | fn result_1zst_non_exhaustive_no_variant_t(x: Result<num::NonZero<u8>, NonExhaustive>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -150,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:132:49
--> $DIR/lint-ctypes-enum.rs:128:49
|
LL | fn result_1zst_exhaustive_single_field_t(x: Result<num::NonZero<u8>, Field>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -159,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:134:30
--> $DIR/lint-ctypes-enum.rs:130: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:145: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:152: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:157:38
--> $DIR/lint-ctypes-enum.rs:151:38
|
LL | fn result_transparent_union_e(x: Result<(), TransparentUnion<num::NonZero<u8>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -193,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:159:30
--> $DIR/lint-ctypes-enum.rs:153:30
|
LL | fn result_repr_rust_e(x: Result<(), Rust<num::NonZero<u8>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -202,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:163:51
--> $DIR/lint-ctypes-enum.rs:157:51
|
LL | fn result_1zst_exhaustive_single_variant_e(x: Result<U, num::NonZero<u8>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -211,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:165:53
--> $DIR/lint-ctypes-enum.rs:159:53
|
LL | fn result_1zst_exhaustive_multiple_variant_e(x: Result<B, num::NonZero<u8>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -220,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:167:51
--> $DIR/lint-ctypes-enum.rs:161:51
|
LL | fn result_1zst_non_exhaustive_no_variant_e(x: Result<NonExhaustive, num::NonZero<u8>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -229,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:170:49
--> $DIR/lint-ctypes-enum.rs:164:49
|
LL | fn result_1zst_exhaustive_single_field_e(x: Result<Field, num::NonZero<u8>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -238,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:172:30
--> $DIR/lint-ctypes-enum.rs:166:30
|
LL | fn result_cascading_e(x: Result<(), Result<(), num::NonZero<u8>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
Expand All @@ -247,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:174:27
--> $DIR/lint-ctypes-enum.rs:168: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 27 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
Expand Up @@ -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)`

Expand All @@ -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`

Expand Down Expand Up @@ -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) { }

Expand Down
Loading
Loading