提交 bd6758a2 编写于 作者: A Alex Crichton

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]: https://github.com/rust-lang/rfcs/pull/1291

This commit disables these lints to instead consider `isize` and `usize` valid
types to have in FFI signatures.
上级 3e6d7243
......@@ -497,14 +497,6 @@ fn check_type_for_ffi(&self,
FfiSafe
}
ty::TyInt(ast::TyIs) => {
FfiUnsafe("found Rust type `isize` in foreign module, while \
`libc::c_int` or `libc::c_long` should be used")
}
ty::TyUint(ast::TyUs) => {
FfiUnsafe("found Rust type `usize` in foreign module, while \
`libc::c_uint` or `libc::c_ulong` should be used")
}
ty::TyChar => {
FfiUnsafe("found Rust type `char` in foreign module, while \
`u32` or `libc::wchar_t` should be used")
......
......@@ -10,8 +10,10 @@
#![deny(warnings)]
pub struct Foo;
extern {
pub fn foo(x: (isize)); //~ ERROR found Rust type `isize` in foreign module
pub fn foo(x: (Foo)); //~ ERROR found struct without
}
fn main() {
......
......@@ -27,12 +27,11 @@ pub struct StructWithProjectionAndLifetime<'a>(
pub type RustFn = fn();
pub type RustBadRet = extern fn() -> Box<u32>;
pub type CVoidRet = ();
pub struct Foo;
extern {
pub fn bare_type1(size: isize); //~ ERROR: found Rust type
pub fn bare_type2(size: usize); //~ ERROR: found Rust type
pub fn ptr_type1(size: *const isize); //~ ERROR: found Rust type
pub fn ptr_type2(size: *const usize); //~ ERROR: found Rust type
pub fn ptr_type1(size: *const Foo); //~ ERROR: found struct without
pub fn ptr_type2(size: *const Foo); //~ ERROR: found struct without
pub fn slice_type(p: &[u32]); //~ ERROR: found Rust slice type
pub fn str_type(p: &str); //~ ERROR: found Rust type
pub fn box_type(p: Box<u32>); //~ ERROR found Rust type
......@@ -55,6 +54,8 @@ pub struct StructWithProjectionAndLifetime<'a>(
pub fn good8(fptr: extern fn() -> !);
pub fn good9() -> ();
pub fn good10() -> CVoidRet;
pub fn good11(size: isize);
pub fn good12(size: usize);
}
fn main() {
......
......@@ -13,9 +13,8 @@
mod xx {
extern {
pub fn strlen(str: *const u8) -> usize; //~ ERROR found Rust type `usize`
pub fn foo(x: isize, y: usize); //~ ERROR found Rust type `isize`
//~^ ERROR found Rust type `usize`
pub fn strlen(str: *const u8) -> usize;
pub fn foo(x: isize, y: usize);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册