Skip to content

Commit 2821fb5

Browse files
committed
TEMP COMMIT, to be deleted on rebase: remove i128/u128 warnings
1 parent c734436 commit 2821fb5

File tree

10 files changed

+47
-223
lines changed

10 files changed

+47
-223
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,6 @@ lint_improper_ctypes = {$desc} uses type `{$ty}`, which is not FFI-safe
374374
.label = not FFI-safe
375375
.note = the type is defined here
376376
377-
lint_improper_ctypes_128bit = 128-bit integers don't currently have a known stable ABI
378-
379377
lint_improper_ctypes_array_help = consider passing a pointer to the array
380378
381379
lint_improper_ctypes_array_reason = passing raw arrays by value is not FFI-safe

compiler/rustc_lint/src/types/improper_ctypes.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cmp::{Eq, PartialEq};
33
use std::iter;
44
use std::ops::ControlFlow;
55

6-
use rustc_abi::{Integer, IntegerType, VariantIdx};
6+
use rustc_abi::VariantIdx;
77
use rustc_data_structures::fx::FxHashSet;
88
use rustc_errors::DiagMessage;
99
use rustc_hir::def::CtorKind;
@@ -582,11 +582,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
582582
}
583583

584584
/// Checks whether an uninhabited type (one without valid values) is safe-ish to have here
585-
fn visit_uninhabited(
586-
&self,
587-
state: CTypesVisitorState,
588-
ty: Ty<'tcx>,
589-
) -> FfiResult<'tcx> {
585+
fn visit_uninhabited(&self, state: CTypesVisitorState, ty: Ty<'tcx>) -> FfiResult<'tcx> {
590586
if state.is_in_function_return() {
591587
FfiResult::FfiSafe
592588
} else {
@@ -604,17 +600,16 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
604600
fn visit_numeric(&self, ty: Ty<'tcx>) -> FfiResult<'tcx> {
605601
// FIXME: for now, this is very incomplete, and seems to assume a x86_64 target
606602
match ty.kind() {
607-
ty::Int(ty::IntTy::I128) | ty::Uint(ty::UintTy::U128) => {
608-
FfiResult::new_with_reason(ty, fluent::lint_improper_ctypes_128bit, None)
609-
}
603+
// note: before rust 1.77, 128-bit ints were not FFI-safe on x86_64
604+
// ...they probably are still unsafe on i686 and other x86_32 architectures
610605
ty::Int(..) | ty::Uint(..) | ty::Float(..) => FfiResult::FfiSafe,
611606

612607
ty::Char => FfiResult::new_with_reason(
613608
ty,
614609
fluent::lint_improper_ctypes_char_reason,
615610
Some(fluent::lint_improper_ctypes_char_help),
616611
),
617-
_ => bug!("visit_numeric is to be called with numeric (int, float) types"),
612+
_ => bug!("visit_numeric is to be called with numeric (char, int, float) types"),
618613
}
619614
}
620615

@@ -984,9 +979,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
984979
);
985980
}
986981

987-
if let Some(IntegerType::Fixed(Integer::I128, _)) = def.repr().int {
988-
return FfiResult::new_with_reason(ty, fluent::lint_improper_ctypes_128bit, None);
989-
}
982+
// FIXME: connect `def.repr().int` to visit_numeric
983+
// (for now it's OK, `repr(char)` doesn't exist and visit_numeric doesn't warn on anything else)
990984

991985
let non_exhaustive = def.variant_list_has_applicable_non_exhaustive();
992986
// Check the contained variants.

tests/ui/asm/naked-functions-ffi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ use std::arch::naked_asm;
77
#[unsafe(naked)]
88
pub extern "C" fn naked(p: char) -> u128 {
99
//~^ WARN uses type `char`
10-
//~| WARN uses type `u128`
1110
naked_asm!("")
1211
}

tests/ui/asm/naked-functions-ffi.stderr

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,5 @@ LL | pub extern "C" fn naked(p: char) -> u128 {
88
= note: the `char` type has no C equivalent
99
= note: `#[warn(improper_c_fn_definitions)]` on by default
1010

11-
warning: `extern` fn uses type `u128`, which is not FFI-safe
12-
--> $DIR/naked-functions-ffi.rs:8:37
13-
|
14-
LL | pub extern "C" fn naked(p: char) -> u128 {
15-
| ^^^^ not FFI-safe
16-
|
17-
= note: 128-bit integers don't currently have a known stable ABI
18-
19-
warning: 2 warnings emitted
11+
warning: 1 warning emitted
2012

tests/ui/lint/improper_ctypes/ctypes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ extern "C" {
7676
pub fn box_type(p: Box<u32>);
7777
pub fn opt_box_type(p: Option<Box<u32>>);
7878
pub fn char_type(p: char); //~ ERROR uses type `char`
79-
pub fn i128_type(p: i128); //~ ERROR uses type `i128`
80-
pub fn u128_type(p: u128); //~ ERROR uses type `u128`
79+
pub fn i128_type(p: i128);
80+
pub fn u128_type(p: u128);
8181
pub fn pat_type1() -> pattern_type!(u32 is 1..);
8282
pub fn pat_type2(p: pattern_type!(u32 is 1..)); // no error!
8383
pub fn trait_type(p: &dyn Bar); //~ ERROR uses type `&dyn Bar`
@@ -91,7 +91,7 @@ extern "C" {
9191
pub fn fn_type(p: RustFn); //~ ERROR uses type `fn()`
9292
pub fn fn_type2(p: fn()); //~ ERROR uses type `fn()`
9393
pub fn fn_contained(p: RustBoxRet);
94-
pub fn transparent_i128(p: TransparentI128); //~ ERROR: uses type `TransparentI128`
94+
pub fn transparent_i128(p: TransparentI128);
9595
pub fn transparent_str(p: TransparentStr); //~ ERROR: uses type `TransparentStr`
9696
pub fn transparent_fn(p: TransparentBoxFn);
9797
pub fn raw_array(arr: [u8; 8]); //~ ERROR: uses type `[u8; 8]`
@@ -110,8 +110,8 @@ extern "C" {
110110
pub fn no_niche_b(b: Option<UnsafeCell<&i32>>);
111111
//~^ ERROR: uses type `Option<UnsafeCell<&i32>>`
112112

113-
pub static static_u128_type: u128; //~ ERROR: uses type `u128`
114-
pub static static_u128_array_type: [u128; 16]; //~ ERROR: uses type `u128`
113+
pub static static_u128_type: u128;
114+
pub static static_u128_array_type: [u128; 16];
115115

116116
pub fn good3(fptr: Option<extern "C" fn()>);
117117
pub fn good4(aptr: &[u8; 4 as usize]);

tests/ui/lint/improper_ctypes/ctypes.stderr

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,6 @@ LL | pub fn char_type(p: char);
3030
= help: consider using `u32` or `libc::wchar_t` instead
3131
= note: the `char` type has no C equivalent
3232

33-
error: `extern` block uses type `i128`, which is not FFI-safe
34-
--> $DIR/ctypes.rs:79:25
35-
|
36-
LL | pub fn i128_type(p: i128);
37-
| ^^^^ not FFI-safe
38-
|
39-
= note: 128-bit integers don't currently have a known stable ABI
40-
41-
error: `extern` block uses type `u128`, which is not FFI-safe
42-
--> $DIR/ctypes.rs:80:25
43-
|
44-
LL | pub fn u128_type(p: u128);
45-
| ^^^^ not FFI-safe
46-
|
47-
= note: 128-bit integers don't currently have a known stable ABI
48-
4933
error: `extern` block uses type `&dyn Bar`, which is not FFI-safe
5034
--> $DIR/ctypes.rs:83:26
5135
|
@@ -125,20 +109,6 @@ LL | pub fn fn_type2(p: fn());
125109
= help: consider using an `extern fn(...) -> ...` function pointer instead
126110
= note: this function pointer has Rust-specific calling convention
127111

128-
error: `extern` block uses type `TransparentI128`, which is not FFI-safe
129-
--> $DIR/ctypes.rs:94:32
130-
|
131-
LL | pub fn transparent_i128(p: TransparentI128);
132-
| ^^^^^^^^^^^^^^^ not FFI-safe
133-
|
134-
= note: this struct/enum/union (`TransparentI128`) is FFI-unsafe due to a `i128` field
135-
note: the type is defined here
136-
--> $DIR/ctypes.rs:34:1
137-
|
138-
LL | pub struct TransparentI128(i128);
139-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
140-
= note: 128-bit integers don't currently have a known stable ABI
141-
142112
error: `extern` block uses type `TransparentStr`, which is not FFI-safe
143113
--> $DIR/ctypes.rs:95:31
144114
|
@@ -229,22 +199,6 @@ LL | pub fn no_niche_b(b: Option<UnsafeCell<&i32>>);
229199
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
230200
= note: enum has no representation hint
231201

232-
error: `extern` block uses type `u128`, which is not FFI-safe
233-
--> $DIR/ctypes.rs:113:34
234-
|
235-
LL | pub static static_u128_type: u128;
236-
| ^^^^ not FFI-safe
237-
|
238-
= note: 128-bit integers don't currently have a known stable ABI
239-
240-
error: `extern` block uses type `u128`, which is not FFI-safe
241-
--> $DIR/ctypes.rs:114:40
242-
|
243-
LL | pub static static_u128_array_type: [u128; 16];
244-
| ^^^^^^^^^^ not FFI-safe
245-
|
246-
= note: 128-bit integers don't currently have a known stable ABI
247-
248202
error: foreign-code-reachable static uses type `&str`, which is not FFI-safe
249203
--> $DIR/ctypes.rs:147:29
250204
|
@@ -259,5 +213,5 @@ note: the lint level is defined here
259213
LL | #![deny(improper_c_fn_definitions, improper_c_var_definitions)]
260214
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
261215

262-
error: aborting due to 25 previous errors
216+
error: aborting due to 20 previous errors
263217

tests/ui/lint/improper_ctypes/lint-enum.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ extern "C" {
8484
fn repr_c(x: ReprC);
8585
fn repr_u8(x: U8);
8686
fn repr_isize(x: Isize);
87-
fn repr_u128(x: U128); //~ ERROR `extern` block uses type `U128`
88-
fn repr_i128(x: I128); //~ ERROR `extern` block uses type `I128`
87+
fn repr_u128(x: U128);
88+
fn repr_i128(x: I128);
8989
fn option_ref(x: Option<&'static u8>);
9090
fn option_fn(x: Option<extern "C" fn()>);
9191
fn option_nonnull(x: Option<std::ptr::NonNull<u8>>);
@@ -95,14 +95,12 @@ extern "C" {
9595
fn option_nonzero_u32(x: Option<num::NonZero<u32>>);
9696
fn option_nonzero_u64(x: Option<num::NonZero<u64>>);
9797
fn option_nonzero_u128(x: Option<num::NonZero<u128>>);
98-
//~^ ERROR `extern` block uses type `u128`
9998
fn option_nonzero_usize(x: Option<num::NonZero<usize>>);
10099
fn option_nonzero_i8(x: Option<num::NonZero<i8>>);
101100
fn option_nonzero_i16(x: Option<num::NonZero<i16>>);
102101
fn option_nonzero_i32(x: Option<num::NonZero<i32>>);
103102
fn option_nonzero_i64(x: Option<num::NonZero<i64>>);
104103
fn option_nonzero_i128(x: Option<num::NonZero<i128>>);
105-
//~^ ERROR `extern` block uses type `i128`
106104
fn option_nonzero_isize(x: Option<num::NonZero<isize>>);
107105
fn option_transparent_struct(x: Option<TransparentStruct<num::NonZero<u8>>>);
108106
fn option_transparent_enum(x: Option<TransparentEnum<num::NonZero<u8>>>);
@@ -120,14 +118,12 @@ extern "C" {
120118
fn result_nonzero_u32_t(x: Result<num::NonZero<u32>, ()>);
121119
fn result_nonzero_u64_t(x: Result<num::NonZero<u64>, ()>);
122120
fn result_nonzero_u128_t(x: Result<num::NonZero<u128>, ()>);
123-
//~^ ERROR `extern` block uses type `u128`
124121
fn result_nonzero_usize_t(x: Result<num::NonZero<usize>, ()>);
125122
fn result_nonzero_i8_t(x: Result<num::NonZero<i8>, ()>);
126123
fn result_nonzero_i16_t(x: Result<num::NonZero<i16>, ()>);
127124
fn result_nonzero_i32_t(x: Result<num::NonZero<i32>, ()>);
128125
fn result_nonzero_i64_t(x: Result<num::NonZero<i64>, ()>);
129126
fn result_nonzero_i128_t(x: Result<num::NonZero<i128>, ()>);
130-
//~^ ERROR `extern` block uses type `i128`
131127
fn result_nonzero_isize_t(x: Result<num::NonZero<isize>, ()>);
132128
fn result_transparent_struct_t(x: Result<TransparentStruct<num::NonZero<u8>>, ()>);
133129
fn result_transparent_enum_t(x: Result<TransparentEnum<num::NonZero<u8>>, ()>);
@@ -158,14 +154,12 @@ extern "C" {
158154
fn result_nonzero_u32_e(x: Result<(), num::NonZero<u32>>);
159155
fn result_nonzero_u64_e(x: Result<(), num::NonZero<u64>>);
160156
fn result_nonzero_u128_e(x: Result<(), num::NonZero<u128>>);
161-
//~^ ERROR `extern` block uses type `u128`
162157
fn result_nonzero_usize_e(x: Result<(), num::NonZero<usize>>);
163158
fn result_nonzero_i8_e(x: Result<(), num::NonZero<i8>>);
164159
fn result_nonzero_i16_e(x: Result<(), num::NonZero<i16>>);
165160
fn result_nonzero_i32_e(x: Result<(), num::NonZero<i32>>);
166161
fn result_nonzero_i64_e(x: Result<(), num::NonZero<i64>>);
167162
fn result_nonzero_i128_e(x: Result<(), num::NonZero<i128>>);
168-
//~^ ERROR `extern` block uses type `i128`
169163
fn result_nonzero_isize_e(x: Result<(), num::NonZero<isize>>);
170164
fn result_transparent_struct_e(x: Result<(), TransparentStruct<num::NonZero<u8>>>);
171165
fn result_transparent_enum_e(x: Result<(), TransparentEnum<num::NonZero<u8>>>);

0 commit comments

Comments
 (0)