Skip to content

Commit a4cbd6a

Browse files
alexcrichtonbrson
authored andcommitted
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 30f4fff commit a4cbd6a

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

src/librustc_lint/builtin.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
557557
FfiSafe
558558
}
559559

560-
ty::TyInt(hir::TyIs) => {
561-
FfiUnsafe("found Rust type `isize` in foreign module, while \
562-
`libc::c_int` or `libc::c_long` should be used")
563-
}
564-
ty::TyUint(hir::TyUs) => {
565-
FfiUnsafe("found Rust type `usize` in foreign module, while \
566-
`libc::c_uint` or `libc::c_ulong` should be used")
567-
}
568560
ty::TyChar => {
569561
FfiUnsafe("found Rust type `char` in foreign module, while \
570562
`u32` or `libc::wchar_t` should be used")

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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 5 additions & 4 deletions
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 renamed to src/test/run-pass/foreign-int-types.rs

Lines changed: 2 additions & 3 deletions
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)