Skip to content

Commit bd6758a

Browse files
committed
rustc: Don't lint about isize/usize in FFI
This lint warning was originally intended to help against misuse of the old Rust `int` and `uint` types in FFI bindings where the Rust `int` was not equal to the C `int`. This confusion no longer exists (as Rust's types are now `isize` and `usize`), and as a result the need for this lint has become much less over time. Additionally, starting with [the RFC for libc][rfc] it's likely that `isize` and `usize` will be quite common in FFI bindings (e.g. they're the definition of `size_t` and `ssize_t` on many platforms). [rfc]: rust-lang/rfcs#1291 This commit disables these lints to instead consider `isize` and `usize` valid types to have in FFI signatures.
1 parent 3e6d724 commit bd6758a

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

src/librustc_lint/types.rs

-8
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
497497
FfiSafe
498498
}
499499

500-
ty::TyInt(ast::TyIs) => {
501-
FfiUnsafe("found Rust type `isize` in foreign module, while \
502-
`libc::c_int` or `libc::c_long` should be used")
503-
}
504-
ty::TyUint(ast::TyUs) => {
505-
FfiUnsafe("found Rust type `usize` in foreign module, while \
506-
`libc::c_uint` or `libc::c_ulong` should be used")
507-
}
508500
ty::TyChar => {
509501
FfiUnsafe("found Rust type `char` in foreign module, while \
510502
`u32` or `libc::wchar_t` should be used")

src/test/compile-fail/issue-16250.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
#![deny(warnings)]
1212

13+
pub struct Foo;
14+
1315
extern {
14-
pub fn foo(x: (isize)); //~ ERROR found Rust type `isize` in foreign module
16+
pub fn foo(x: (Foo)); //~ ERROR found struct without
1517
}
1618

1719
fn main() {

src/test/compile-fail/lint-ctypes.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ pub struct ZeroSize;
2727
pub type RustFn = fn();
2828
pub type RustBadRet = extern fn() -> Box<u32>;
2929
pub type CVoidRet = ();
30+
pub struct Foo;
3031

3132
extern {
32-
pub fn bare_type1(size: isize); //~ ERROR: found Rust type
33-
pub fn bare_type2(size: usize); //~ ERROR: found Rust type
34-
pub fn ptr_type1(size: *const isize); //~ ERROR: found Rust type
35-
pub fn ptr_type2(size: *const usize); //~ ERROR: found Rust type
33+
pub fn ptr_type1(size: *const Foo); //~ ERROR: found struct without
34+
pub fn ptr_type2(size: *const Foo); //~ ERROR: found struct without
3635
pub fn slice_type(p: &[u32]); //~ ERROR: found Rust slice type
3736
pub fn str_type(p: &str); //~ ERROR: found Rust type
3837
pub fn box_type(p: Box<u32>); //~ ERROR found Rust type
@@ -55,6 +54,8 @@ extern {
5554
pub fn good8(fptr: extern fn() -> !);
5655
pub fn good9() -> ();
5756
pub fn good10() -> CVoidRet;
57+
pub fn good11(size: isize);
58+
pub fn good12(size: usize);
5859
}
5960

6061
fn main() {

src/test/compile-fail/warn-foreign-int-types.rs src/test/run-pass/foreign-int-types.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313

1414
mod xx {
1515
extern {
16-
pub fn strlen(str: *const u8) -> usize; //~ ERROR found Rust type `usize`
17-
pub fn foo(x: isize, y: usize); //~ ERROR found Rust type `isize`
18-
//~^ ERROR found Rust type `usize`
16+
pub fn strlen(str: *const u8) -> usize;
17+
pub fn foo(x: isize, y: usize);
1918
}
2019
}
2120

0 commit comments

Comments
 (0)