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
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 @@ -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
Expand Down
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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,

Expand Down
14 changes: 14 additions & 0 deletions library/core/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

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

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 @@ -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
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: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
Expand Up @@ -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>>);
Expand All @@ -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>>>);
Expand All @@ -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>>, ()>);
Expand Down Expand Up @@ -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>>>);
Expand Down
112 changes: 19 additions & 93 deletions tests/ui/lint/lint-ctypes-enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Loading
Loading