1
Fork 0

Update tests for extern block linting

This commit is contained in:
Mark Rousskov 2020-09-01 17:12:52 -04:00
parent c4a8d7f86a
commit 8a3edb1d66
285 changed files with 1010 additions and 947 deletions

View file

@ -3,13 +3,13 @@ You cannot use type or const parameters on foreign items.
Example of erroneous code: Example of erroneous code:
```compile_fail,E0044 ```compile_fail,E0044
extern { fn some_func<T>(x: T); } extern "C" { fn some_func<T>(x: T); }
``` ```
To fix this, replace the generic parameter with the specializations that you To fix this, replace the generic parameter with the specializations that you
need: need:
``` ```
extern { fn some_func_i32(x: i32); } extern "C" { fn some_func_i32(x: i32); }
extern { fn some_func_i64(x: i64); } extern "C" { fn some_func_i64(x: i64); }
``` ```

View file

@ -3,7 +3,7 @@ A pattern was declared as an argument in a foreign function declaration.
Erroneous code example: Erroneous code example:
```compile_fail,E0130 ```compile_fail,E0130
extern { extern "C" {
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
// function declarations // function declarations
} }
@ -17,7 +17,7 @@ struct SomeStruct {
b: u32, b: u32,
} }
extern { extern "C" {
fn foo(s: SomeStruct); // ok! fn foo(s: SomeStruct); // ok!
} }
``` ```
@ -25,7 +25,7 @@ extern {
Or: Or:
``` ```
extern { extern "C" {
fn foo(a: (u32, u32)); // ok! fn foo(a: (u32, u32)); // ok!
} }
``` ```

View file

@ -3,7 +3,7 @@ A link name was given with an empty name.
Erroneous code example: Erroneous code example:
```compile_fail,E0454 ```compile_fail,E0454
#[link(name = "")] extern {} #[link(name = "")] extern "C" {}
// error: `#[link(name = "")]` given with empty name // error: `#[link(name = "")]` given with empty name
``` ```
@ -11,5 +11,5 @@ The rust compiler cannot link to an external library if you don't give it its
name. Example: name. Example:
```no_run ```no_run
#[link(name = "some_lib")] extern {} // ok! #[link(name = "some_lib")] extern "C" {} // ok!
``` ```

View file

@ -4,7 +4,7 @@ as frameworks are specific to that operating system.
Erroneous code example: Erroneous code example:
```ignore (should-compile_fail-but-cannot-doctest-conditionally-without-macos) ```ignore (should-compile_fail-but-cannot-doctest-conditionally-without-macos)
#[link(name = "FooCoreServices", kind = "framework")] extern {} #[link(name = "FooCoreServices", kind = "framework")] extern "C" {}
// OS used to compile is Linux for example // OS used to compile is Linux for example
``` ```
@ -12,7 +12,7 @@ To solve this error you can use conditional compilation:
``` ```
#[cfg_attr(target="macos", link(name = "FooCoreServices", kind = "framework"))] #[cfg_attr(target="macos", link(name = "FooCoreServices", kind = "framework"))]
extern {} extern "C" {}
``` ```
Learn more in the [Conditional Compilation][conditional-compilation] section Learn more in the [Conditional Compilation][conditional-compilation] section

View file

@ -3,7 +3,7 @@ An unknown "kind" was specified for a link attribute.
Erroneous code example: Erroneous code example:
```compile_fail,E0458 ```compile_fail,E0458
#[link(kind = "wonderful_unicorn")] extern {} #[link(kind = "wonderful_unicorn")] extern "C" {}
// error: unknown kind: `wonderful_unicorn` // error: unknown kind: `wonderful_unicorn`
``` ```

View file

@ -3,7 +3,7 @@ A link was used without a name parameter.
Erroneous code example: Erroneous code example:
```compile_fail,E0459 ```compile_fail,E0459
#[link(kind = "dylib")] extern {} #[link(kind = "dylib")] extern "C" {}
// error: `#[link(...)]` specified without `name = "foo"` // error: `#[link(...)]` specified without `name = "foo"`
``` ```
@ -11,5 +11,5 @@ Please add the name parameter to allow the rust compiler to find the library
you want. Example: you want. Example:
```no_run ```no_run
#[link(kind = "dylib", name = "some_lib")] extern {} // ok! #[link(kind = "dylib", name = "some_lib")] extern "C" {} // ok!
``` ```

View file

@ -3,7 +3,7 @@ Attempted to pass an invalid type of variable into a variadic function.
Erroneous code example: Erroneous code example:
```compile_fail,E0617 ```compile_fail,E0617
extern { extern "C" {
fn printf(c: *const i8, ...); fn printf(c: *const i8, ...);
} }
@ -21,7 +21,7 @@ to import from `std::os::raw`).
In this case, `c_double` has the same size as `f64` so we can use it directly: In this case, `c_double` has the same size as `f64` so we can use it directly:
```no_run ```no_run
# extern { # extern "C" {
# fn printf(c: *const i8, ...); # fn printf(c: *const i8, ...);
# } # }
unsafe { unsafe {

View file

@ -18,7 +18,7 @@ the function inside of an `extern` block.
``` ```
#![feature(ffi_returns_twice)] #![feature(ffi_returns_twice)]
extern { extern "C" {
#[ffi_returns_twice] // ok! #[ffi_returns_twice] // ok!
pub fn foo(); pub fn foo();
} }

View file

@ -38,7 +38,7 @@ pub fn initialize_available_targets() {
($cfg:meta, $($method:ident),*) => { { ($cfg:meta, $($method:ident),*) => { {
#[cfg($cfg)] #[cfg($cfg)]
fn init() { fn init() {
extern { extern "C" {
$(fn $method();)* $(fn $method();)*
} }
unsafe { unsafe {

View file

@ -809,7 +809,7 @@ impl AtomicBool {
/// ```ignore (extern-declaration) /// ```ignore (extern-declaration)
/// # fn main() { /// # fn main() {
/// use std::sync::atomic::AtomicBool; /// use std::sync::atomic::AtomicBool;
/// extern { /// extern "C" {
/// fn my_atomic_op(arg: *mut bool); /// fn my_atomic_op(arg: *mut bool);
/// } /// }
/// ///
@ -2068,7 +2068,7 @@ macro_rules! atomic_int {
/// # fn main() { /// # fn main() {
#[doc = concat!($extra_feature, "use std::sync::atomic::", stringify!($atomic_type), ";")] #[doc = concat!($extra_feature, "use std::sync::atomic::", stringify!($atomic_type), ";")]
/// ///
/// extern { /// extern "C" {
#[doc = concat!(" fn my_atomic_op(arg: *mut ", stringify!($int_type), ");")] #[doc = concat!(" fn my_atomic_op(arg: *mut ", stringify!($int_type), ");")]
/// } /// }
/// ///

View file

@ -86,7 +86,7 @@ use crate::sys;
/// use std::ffi::CString; /// use std::ffi::CString;
/// use std::os::raw::c_char; /// use std::os::raw::c_char;
/// ///
/// extern { /// extern "C" {
/// fn my_printer(s: *const c_char); /// fn my_printer(s: *const c_char);
/// } /// }
/// ///
@ -144,7 +144,7 @@ pub struct CString {
/// use std::ffi::CStr; /// use std::ffi::CStr;
/// use std::os::raw::c_char; /// use std::os::raw::c_char;
/// ///
/// extern { fn my_string() -> *const c_char; } /// extern "C" { fn my_string() -> *const c_char; }
/// ///
/// unsafe { /// unsafe {
/// let slice = CStr::from_ptr(my_string()); /// let slice = CStr::from_ptr(my_string());
@ -159,7 +159,7 @@ pub struct CString {
/// use std::os::raw::c_char; /// use std::os::raw::c_char;
/// ///
/// fn work(data: &CStr) { /// fn work(data: &CStr) {
/// extern { fn work_with(data: *const c_char); } /// extern "C" { fn work_with(data: *const c_char); }
/// ///
/// unsafe { work_with(data.as_ptr()) } /// unsafe { work_with(data.as_ptr()) }
/// } /// }
@ -174,7 +174,7 @@ pub struct CString {
/// use std::ffi::CStr; /// use std::ffi::CStr;
/// use std::os::raw::c_char; /// use std::os::raw::c_char;
/// ///
/// extern { fn my_string() -> *const c_char; } /// extern "C" { fn my_string() -> *const c_char; }
/// ///
/// fn my_string_safe() -> String { /// fn my_string_safe() -> String {
/// unsafe { /// unsafe {
@ -359,7 +359,7 @@ impl CString {
/// use std::ffi::CString; /// use std::ffi::CString;
/// use std::os::raw::c_char; /// use std::os::raw::c_char;
/// ///
/// extern { fn puts(s: *const c_char); } /// extern "C" { fn puts(s: *const c_char); }
/// ///
/// let to_print = CString::new("Hello!").expect("CString::new failed"); /// let to_print = CString::new("Hello!").expect("CString::new failed");
/// unsafe { /// unsafe {
@ -465,7 +465,7 @@ impl CString {
/// use std::ffi::CString; /// use std::ffi::CString;
/// use std::os::raw::c_char; /// use std::os::raw::c_char;
/// ///
/// extern { /// extern "C" {
/// fn some_extern_function(s: *mut c_char); /// fn some_extern_function(s: *mut c_char);
/// } /// }
/// ///
@ -1147,7 +1147,7 @@ impl CStr {
/// use std::ffi::CStr; /// use std::ffi::CStr;
/// use std::os::raw::c_char; /// use std::os::raw::c_char;
/// ///
/// extern { /// extern "C" {
/// fn my_string() -> *const c_char; /// fn my_string() -> *const c_char;
/// } /// }
/// ///

View file

@ -15,7 +15,7 @@ usage would be:
#![feature(link_args)] #![feature(link_args)]
#[link_args = "-foo -bar -baz"] #[link_args = "-foo -bar -baz"]
extern {} extern "C" {}
# fn main() {} # fn main() {}
``` ```

View file

@ -13,7 +13,7 @@ impl Drop for A {
} }
} }
extern { extern "C" {
#[link_name = "llvm.sqrt.f32"] #[link_name = "llvm.sqrt.f32"]
fn sqrt(x: f32) -> f32; fn sqrt(x: f32) -> f32;
} }

View file

@ -8,7 +8,7 @@ struct A;
impl Drop for A { impl Drop for A {
fn drop(&mut self) { fn drop(&mut self) {
extern { fn foo(); } extern "C" { fn foo(); }
unsafe { foo(); } unsafe { foo(); }
} }
} }

View file

@ -18,7 +18,7 @@ fn main() {
} }
} }
extern { extern "C" {
fn giraffe(); fn giraffe();
fn turtle(); fn turtle();
} }

View file

@ -4,7 +4,7 @@
pub fn bar() { unsafe { foo() } } pub fn bar() { unsafe { foo() } }
extern { extern "C" {
// CHECK-LABEL: declare void @foo() // CHECK-LABEL: declare void @foo()
// CHECK-SAME: [[ATTRS:#[0-9]+]] // CHECK-SAME: [[ATTRS:#[0-9]+]]
// CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readnone{{.*}} } // CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readnone{{.*}} }

View file

@ -11,7 +11,7 @@ struct S {
f3: i32, f3: i32,
} }
extern { extern "C" {
fn foo(s: S); fn foo(s: S);
} }

View file

@ -4,7 +4,7 @@
pub fn bar() { unsafe { foo() } } pub fn bar() { unsafe { foo() } }
extern { extern "C" {
// CHECK-LABEL: declare void @foo() // CHECK-LABEL: declare void @foo()
// CHECK-SAME: [[ATTRS:#[0-9]+]] // CHECK-SAME: [[ATTRS:#[0-9]+]]
// CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readonly{{.*}} } // CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readonly{{.*}} }

View file

@ -4,7 +4,7 @@
pub fn bar() { unsafe { foo() } } pub fn bar() { unsafe { foo() } }
extern { extern "C" {
// CHECK-LABEL: declare void @foo() // CHECK-LABEL: declare void @foo()
// CHECK-SAME: [[ATTRS:#[0-9]+]] // CHECK-SAME: [[ATTRS:#[0-9]+]]
// CHECK-DAG: attributes [[ATTRS]] = { {{.*}}returns_twice{{.*}} } // CHECK-DAG: attributes [[ATTRS]] = { {{.*}}returns_twice{{.*}} }

View file

@ -13,7 +13,7 @@ impl Drop for A {
} }
} }
extern { extern "C" {
#[link_name = "llvm.sqrt.f32"] #[link_name = "llvm.sqrt.f32"]
fn sqrt(x: f32) -> f32; fn sqrt(x: f32) -> f32;
} }

View file

@ -4,7 +4,7 @@
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(unwind_attributes)] #![feature(unwind_attributes)]
extern { extern "C" {
// CHECK: Function Attrs:{{.*}}nounwind // CHECK: Function Attrs:{{.*}}nounwind
// CHECK-NEXT: declare void @extern_fn // CHECK-NEXT: declare void @extern_fn
fn extern_fn(); fn extern_fn();

View file

@ -23,7 +23,6 @@
// gdbg-check:type = struct Struct2 // gdbg-check:type = struct Struct2
// gdbr-check:type = type_names::mod1::Struct2 // gdbr-check:type = type_names::mod1::Struct2
// ENUMS // ENUMS
// gdb-command:whatis simple_enum_1 // gdb-command:whatis simple_enum_1
// gdbg-check:type = union Enum1 // gdbg-check:type = union Enum1
@ -45,7 +44,6 @@
// gdbg-check:type = union Enum3<type_names::Struct1> // gdbg-check:type = union Enum3<type_names::Struct1>
// gdbr-check:type = type_names::mod1::mod2::Enum3<type_names::Struct1> // gdbr-check:type = type_names::mod1::mod2::Enum3<type_names::Struct1>
// TUPLES // TUPLES
// gdb-command:whatis tuple1 // gdb-command:whatis tuple1
// gdbg-check:type = struct (u32, type_names::Struct1, type_names::mod1::mod2::Enum3<type_names::mod1::Struct2>) // gdbg-check:type = struct (u32, type_names::Struct1, type_names::mod1::mod2::Enum3<type_names::mod1::Struct2>)
@ -55,7 +53,6 @@
// gdbg-check:type = struct ((type_names::Struct1, type_names::mod1::mod2::Struct3), type_names::mod1::Enum2, char) // gdbg-check:type = struct ((type_names::Struct1, type_names::mod1::mod2::Struct3), type_names::mod1::Enum2, char)
// gdbr-check:type = ((type_names::Struct1, type_names::mod1::mod2::Struct3), type_names::mod1::Enum2, char) // gdbr-check:type = ((type_names::Struct1, type_names::mod1::mod2::Struct3), type_names::mod1::Enum2, char)
// BOX // BOX
// gdb-command:whatis box1 // gdb-command:whatis box1
// gdbg-check:type = struct (alloc::boxed::Box<f32>, i32) // gdbg-check:type = struct (alloc::boxed::Box<f32>, i32)
@ -65,7 +62,6 @@
// gdbg-check:type = struct (alloc::boxed::Box<type_names::mod1::mod2::Enum3<f32>>, i32) // gdbg-check:type = struct (alloc::boxed::Box<type_names::mod1::mod2::Enum3<f32>>, i32)
// gdbr-check:type = (alloc::boxed::Box<type_names::mod1::mod2::Enum3<f32>>, i32) // gdbr-check:type = (alloc::boxed::Box<type_names::mod1::mod2::Enum3<f32>>, i32)
// REFERENCES // REFERENCES
// gdb-command:whatis ref1 // gdb-command:whatis ref1
// gdbg-check:type = struct (&type_names::Struct1, i32) // gdbg-check:type = struct (&type_names::Struct1, i32)
@ -83,7 +79,6 @@
// gdbg-check:type = struct (&mut type_names::GenericStruct<type_names::mod1::Enum2, f64>, i32) // gdbg-check:type = struct (&mut type_names::GenericStruct<type_names::mod1::Enum2, f64>, i32)
// gdbr-check:type = (&mut type_names::GenericStruct<type_names::mod1::Enum2, f64>, i32) // gdbr-check:type = (&mut type_names::GenericStruct<type_names::mod1::Enum2, f64>, i32)
// RAW POINTERS // RAW POINTERS
// gdb-command:whatis mut_ptr1 // gdb-command:whatis mut_ptr1
// gdbg-check:type = struct (*mut type_names::Struct1, isize) // gdbg-check:type = struct (*mut type_names::Struct1, isize)
@ -109,7 +104,6 @@
// gdbg-check:type = struct (*const type_names::mod1::mod2::Enum3<type_names::Struct1>, isize) // gdbg-check:type = struct (*const type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
// gdbr-check:type = (*const type_names::mod1::mod2::Enum3<type_names::Struct1>, isize) // gdbr-check:type = (*const type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
// VECTORS // VECTORS
// gdb-command:whatis fixed_size_vec1 // gdb-command:whatis fixed_size_vec1
// gdbg-check:type = struct ([type_names::Struct1; 3], i16) // gdbg-check:type = struct ([type_names::Struct1; 3], i16)
@ -127,7 +121,6 @@
// gdbg-check:type = struct &[type_names::mod1::Enum2] // gdbg-check:type = struct &[type_names::mod1::Enum2]
// gdbr-check:type = &[type_names::mod1::Enum2] // gdbr-check:type = &[type_names::mod1::Enum2]
// TRAITS // TRAITS
// gdb-command:whatis box_trait // gdb-command:whatis box_trait
// gdbg-check:type = struct Box<Trait1> // gdbg-check:type = struct Box<Trait1>
@ -153,7 +146,6 @@
// gdbg-check:type = struct &mut Trait2<type_names::mod1::mod2::Struct3, type_names::GenericStruct<usize, isize>> // gdbg-check:type = struct &mut Trait2<type_names::mod1::mod2::Struct3, type_names::GenericStruct<usize, isize>>
// gdbr-check:type = type_names::&mut Trait2<type_names::mod1::mod2::Struct3, type_names::GenericStruct<usize, isize>> // gdbr-check:type = type_names::&mut Trait2<type_names::mod1::mod2::Struct3, type_names::GenericStruct<usize, isize>>
// BARE FUNCTIONS // BARE FUNCTIONS
// gdb-command:whatis rust_fn // gdb-command:whatis rust_fn
// gdbg-check:type = struct (fn(core::option::Option<isize>, core::option::Option<&type_names::mod1::Struct2>), usize) // gdbg-check:type = struct (fn(core::option::Option<isize>, core::option::Option<&type_names::mod1::Struct2>), usize)
@ -199,7 +191,6 @@
// gdbg-check:type = struct (unsafe extern "C" fn(*const u8, ...) -> isize, usize) // gdbg-check:type = struct (unsafe extern "C" fn(*const u8, ...) -> isize, usize)
// gdbr-check:type = (unsafe extern "C" fn(*const u8, ...) -> isize, usize) // gdbr-check:type = (unsafe extern "C" fn(*const u8, ...) -> isize, usize)
// CLOSURES // CLOSURES
// gdb-command:whatis closure1 // gdb-command:whatis closure1
// gdbg-check:type = struct (closure, usize) // gdbg-check:type = struct (closure, usize)
@ -219,7 +210,7 @@ use std::marker::PhantomData;
use std::ptr; use std::ptr;
pub struct Struct1; pub struct Struct1;
struct GenericStruct<T1, T2>(PhantomData<(T1,T2)>); struct GenericStruct<T1, T2>(PhantomData<(T1, T2)>);
enum Enum1 { enum Enum1 {
Variant1, Variant1,
@ -246,8 +237,12 @@ mod mod1 {
} }
} }
trait Trait1 { fn dummy(&self) { } } trait Trait1 {
trait Trait2<T1, T2> { fn dummy(&self, _: T1, _:T2) { } } fn dummy(&self) {}
}
trait Trait2<T1, T2> {
fn dummy(&self, _: T1, _: T2) {}
}
impl Trait1 for isize {} impl Trait1 for isize {}
impl<T1, T2> Trait2<T1, T2> for isize {} impl<T1, T2> Trait2<T1, T2> for isize {}
@ -257,16 +252,26 @@ extern "C" fn extern_c_fn(_: isize) {}
unsafe fn unsafe_fn(_: Result<char, f64>) {} unsafe fn unsafe_fn(_: Result<char, f64>) {}
extern "stdcall" fn extern_stdcall_fn() {} extern "stdcall" fn extern_stdcall_fn() {}
fn rust_fn_with_return_value(_: f64) -> usize { 4 } fn rust_fn_with_return_value(_: f64) -> usize {
extern "C" fn extern_c_fn_with_return_value() -> Struct1 { Struct1 } 4
unsafe fn unsafe_fn_with_return_value(_: GenericStruct<u16, u8>) -> mod1::Struct2 { mod1::Struct2 } }
extern "stdcall" fn extern_stdcall_fn_with_return_value(_: Box<isize>) -> usize { 0 } extern "C" fn extern_c_fn_with_return_value() -> Struct1 {
Struct1
}
unsafe fn unsafe_fn_with_return_value(_: GenericStruct<u16, u8>) -> mod1::Struct2 {
mod1::Struct2
}
extern "stdcall" fn extern_stdcall_fn_with_return_value(_: Box<isize>) -> usize {
0
}
fn generic_function<T>(x: T) -> T { x } fn generic_function<T>(x: T) -> T {
x
}
#[allow(improper_ctypes)] #[allow(improper_ctypes)]
extern { extern "C" {
fn printf(_:*const u8, ...) -> isize; fn printf(_: *const u8, ...) -> isize;
} }
// In many of the cases below, the type that is actually under test is wrapped // In many of the cases below, the type that is actually under test is wrapped
@ -277,7 +282,6 @@ extern {
// printed correctly, so the tests below just construct a tuple type that will // printed correctly, so the tests below just construct a tuple type that will
// then *contain* the type name that we want to see. // then *contain* the type name that we want to see.
fn main() { fn main() {
// Structs // Structs
let simple_struct = Struct1; let simple_struct = Struct1;
let generic_struct1: GenericStruct<mod1::Struct2, mod1::mod2::Struct3> = let generic_struct1: GenericStruct<mod1::Struct2, mod1::mod2::Struct3> =
@ -339,8 +343,8 @@ fn main() {
let generic_ref_trait = (&0_isize) as &Trait2<Struct1, Struct1>; let generic_ref_trait = (&0_isize) as &Trait2<Struct1, Struct1>;
let mut generic_mut_ref_trait_impl = 0_isize; let mut generic_mut_ref_trait_impl = 0_isize;
let generic_mut_ref_trait = (&mut generic_mut_ref_trait_impl) as let generic_mut_ref_trait = (&mut generic_mut_ref_trait_impl)
&mut Trait2<mod1::mod2::Struct3, GenericStruct<usize, isize>>; as &mut Trait2<mod1::mod2::Struct3, GenericStruct<usize, isize>>;
// Bare Functions // Bare Functions
let rust_fn = (rust_fn, 0_usize); let rust_fn = (rust_fn, 0_usize);
@ -364,11 +368,13 @@ fn main() {
// how that maps to rustc's internal representation of these forms. // how that maps to rustc's internal representation of these forms.
// Once closures have reached their 1.0 form, the tests below should // Once closures have reached their 1.0 form, the tests below should
// probably be expanded. // probably be expanded.
let closure1 = (|x:isize| {}, 0_usize); let closure1 = (|x: isize| {}, 0_usize);
let closure2 = (|x:i8, y: f32| { (x as f32) + y }, 0_usize); let closure2 = (|x: i8, y: f32| (x as f32) + y, 0_usize);
zzz(); // #break zzz(); // #break
} }
#[inline(never)] #[inline(never)]
fn zzz() { () } fn zzz() {
()
}

View file

@ -13,7 +13,7 @@ use std::ffi::CString;
mod mlibc { mod mlibc {
use libc::{c_char, c_long, c_longlong}; use libc::{c_char, c_long, c_longlong};
extern { extern "C" {
pub fn atol(x: *const c_char) -> c_long; pub fn atol(x: *const c_char) -> c_long;
pub fn atoll(x: *const c_char) -> c_longlong; pub fn atoll(x: *const c_char) -> c_longlong;
} }
@ -31,6 +31,8 @@ fn atoll(s: String) -> i64 {
pub fn main() { pub fn main() {
assert_eq!(atol("1024".to_string()) * 10, atol("10240".to_string())); assert_eq!(atol("1024".to_string()) * 10, atol("10240".to_string()));
assert_eq!((atoll("11111111111111111".to_string()) * 10), assert_eq!(
atoll("111111111111111110".to_string())); (atoll("11111111111111111".to_string()) * 10),
atoll("111111111111111110".to_string())
);
} }

View file

@ -1,7 +1,7 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
#[link(name = "foo", kind = "static")] #[link(name = "foo", kind = "static")]
extern { extern "C" {
fn foo(); fn foo();
fn bar(); fn bar();
} }

View file

@ -1,7 +1,7 @@
#![crate_type = "dylib"] #![crate_type = "dylib"]
#[link(name = "cfoo")] #[link(name = "cfoo")]
extern { extern "C" {
fn foo(); fn foo();
} }

View file

@ -1,7 +1,7 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
#[link(name = "cfoo")] #[link(name = "cfoo")]
extern { extern "C" {
fn foo(); fn foo();
} }

View file

@ -1,7 +1,7 @@
#![crate_type = "dylib"] #![crate_type = "dylib"]
#[link(name = "cfoo", kind = "static")] #[link(name = "cfoo", kind = "static")]
extern { extern "C" {
fn foo(); fn foo();
} }

View file

@ -1,7 +1,7 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
#[link(name = "cfoo", kind = "static")] #[link(name = "cfoo", kind = "static")]
extern { extern "C" {
fn foo(); fn foo();
} }

View file

@ -1,4 +1,4 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
#[link(name = "native", kind = "static")] #[link(name = "native", kind = "static")]
extern {} extern "C" {}

View file

@ -1,6 +1,10 @@
extern { fn foo(); } extern "C" {
fn foo();
}
pub fn main() { pub fn main() {
unsafe { foo(); } unsafe {
foo();
}
assert_eq!(7f32.powi(3), 343f32); assert_eq!(7f32.powi(3), 343f32);
} }

View file

@ -1,22 +1,20 @@
extern crate testcrate; extern crate testcrate;
extern "C" fn bar<T>(ts: testcrate::TestStruct<T>) -> T { ts.y } extern "C" fn bar<T>(ts: testcrate::TestStruct<T>) -> T {
ts.y
}
#[link(name = "test", kind = "static")] #[link(name = "test", kind = "static")]
extern { extern "C" {
fn call(c: extern "C" fn(testcrate::TestStruct<i32>) -> i32) -> i32; fn call(c: extern "C" fn(testcrate::TestStruct<i32>) -> i32) -> i32;
} }
fn main() { fn main() {
// Let's test calling it cross crate // Let's test calling it cross crate
let back = unsafe { let back = unsafe { testcrate::call(testcrate::foo::<i32>) };
testcrate::call(testcrate::foo::<i32>)
};
assert_eq!(3, back); assert_eq!(3, back);
// And just within this crate // And just within this crate
let back = unsafe { let back = unsafe { call(bar::<i32>) };
call(bar::<i32>)
};
assert_eq!(3, back); assert_eq!(3, back);
} }

View file

@ -3,12 +3,14 @@
#[repr(C)] #[repr(C)]
pub struct TestStruct<T> { pub struct TestStruct<T> {
pub x: u8, pub x: u8,
pub y: T pub y: T,
} }
pub extern "C" fn foo<T>(ts: TestStruct<T>) -> T { ts.y } pub extern "C" fn foo<T>(ts: TestStruct<T>) -> T {
ts.y
}
#[link(name = "test", kind = "static")] #[link(name = "test", kind = "static")]
extern { extern "C" {
pub fn call(c: extern "C" fn(TestStruct<i32>) -> i32) -> i32; pub fn call(c: extern "C" fn(TestStruct<i32>) -> i32) -> i32;
} }

View file

@ -1,11 +1,15 @@
#[no_mangle] #[no_mangle]
pub extern "C" fn foo() -> i32 { 3 } pub extern "C" fn foo() -> i32 {
3
}
#[no_mangle] #[no_mangle]
pub extern "C" fn bar() -> i32 { 5 } pub extern "C" fn bar() -> i32 {
5
}
#[link(name = "test", kind = "static")] #[link(name = "test", kind = "static")]
extern { extern "C" {
fn add() -> i32; fn add() -> i32;
} }

View file

@ -7,7 +7,7 @@ struct Rect {
a: i32, a: i32,
b: i32, b: i32,
c: i32, c: i32,
d: i32 d: i32,
} }
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
@ -15,7 +15,7 @@ struct Rect {
struct BiggerRect { struct BiggerRect {
s: Rect, s: Rect,
a: i32, a: i32,
b: i32 b: i32,
} }
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
@ -23,7 +23,7 @@ struct BiggerRect {
struct FloatRect { struct FloatRect {
a: i32, a: i32,
b: i32, b: i32,
c: f64 c: f64,
} }
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
@ -33,14 +33,14 @@ struct Huge {
b: i32, b: i32,
c: i32, c: i32,
d: i32, d: i32,
e: i32 e: i32,
} }
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
#[repr(C)] #[repr(C)]
struct FloatPoint { struct FloatPoint {
x: f64, x: f64,
y: f64 y: f64,
} }
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
@ -58,13 +58,22 @@ struct IntOdd {
} }
#[link(name = "test", kind = "static")] #[link(name = "test", kind = "static")]
extern { extern "C" {
fn byval_rect(a: i32, b: i32, c: i32, d: i32, e: i32, s: Rect); fn byval_rect(a: i32, b: i32, c: i32, d: i32, e: i32, s: Rect);
fn byval_many_rect(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, s: Rect); fn byval_many_rect(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, s: Rect);
fn byval_rect_floats(a: f32, b: f32, c: f64, d: f32, e: f32, fn byval_rect_floats(
f: f32, g: f64, s: Rect, t: FloatRect); a: f32,
b: f32,
c: f64,
d: f32,
e: f32,
f: f32,
g: f64,
s: Rect,
t: FloatRect,
);
fn byval_rect_with_float(a: i32, b: i32, c: f32, d: i32, e: i32, f: i32, s: Rect); fn byval_rect_with_float(a: i32, b: i32, c: f32, d: i32, e: i32, f: i32, s: Rect);
@ -107,12 +116,7 @@ fn main() {
byval_many_rect(1, 2, 3, 4, 5, 6, s); byval_many_rect(1, 2, 3, 4, 5, 6, s);
byval_rect_floats(1., 2., 3., 4., 5., 6., 7., s, u); byval_rect_floats(1., 2., 3., 4., 5., 6., 7., s, u);
byval_rect_with_float(1, 2, 3.0, 4, 5, 6, s); byval_rect_with_float(1, 2, 3.0, 4, 5, 6, s);
byval_rect_with_many_huge(v, v, v, v, v, v, Rect { byval_rect_with_many_huge(v, v, v, v, v, v, Rect { a: 123, b: 456, c: 789, d: 420 });
a: 123,
b: 456,
c: 789,
d: 420
});
split_rect(1, 2, s); split_rect(1, 2, s);
split_rect_floats(1., 2., u); split_rect_floats(1., 2., u);
split_rect_with_floats(1, 2, 3.0, 4, 5.0, 6, s); split_rect_with_floats(1, 2, 3.0, 4, 5.0, 6, s);

View file

@ -1,7 +1,7 @@
#![feature(extern_types)] #![feature(extern_types)]
#[link(name = "ctest", kind = "static")] #[link(name = "ctest", kind = "static")]
extern { extern "C" {
type data; type data;
fn data_create(magic: u32) -> *mut data; fn data_create(magic: u32) -> *mut data;

View file

@ -3,11 +3,11 @@
struct Foo { struct Foo {
a: i8, a: i8,
b: i16, b: i16,
c: i8 c: i8,
} }
#[link(name = "test", kind = "static")] #[link(name = "test", kind = "static")]
extern { extern "C" {
fn foo(f: Foo) -> Foo; fn foo(f: Foo) -> Foo;
} }

View file

@ -2,7 +2,7 @@ extern crate testcrate;
use std::mem; use std::mem;
extern { extern "C" {
fn give_back(tu: testcrate::TestUnion) -> u64; fn give_back(tu: testcrate::TestUnion) -> u64;
} }
@ -10,14 +10,10 @@ fn main() {
let magic: u64 = 0xDEADBEEF; let magic: u64 = 0xDEADBEEF;
// Let's test calling it cross crate // Let's test calling it cross crate
let back = unsafe { let back = unsafe { testcrate::give_back(mem::transmute(magic)) };
testcrate::give_back(mem::transmute(magic))
};
assert_eq!(magic, back); assert_eq!(magic, back);
// And just within this crate // And just within this crate
let back = unsafe { let back = unsafe { give_back(mem::transmute(magic)) };
give_back(mem::transmute(magic))
};
assert_eq!(magic, back); assert_eq!(magic, back);
} }

View file

@ -2,10 +2,10 @@
#[repr(C)] #[repr(C)]
pub struct TestUnion { pub struct TestUnion {
_val: u64 _val: u64,
} }
#[link(name = "ctest", kind = "static")] #[link(name = "ctest", kind = "static")]
extern { extern "C" {
pub fn give_back(tu: TestUnion) -> u64; pub fn give_back(tu: TestUnion) -> u64;
} }

View file

@ -3,10 +3,12 @@
extern crate foo; extern crate foo;
#[link(name = "bar", kind = "static")] #[link(name = "bar", kind = "static")]
extern { extern "C" {
fn bar(); fn bar();
} }
pub fn doit() { pub fn doit() {
unsafe { bar(); } unsafe {
bar();
}
} }

View file

@ -1,10 +1,12 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
#[link(name = "foo", kind = "static")] #[link(name = "foo", kind = "static")]
extern { extern "C" {
fn foo(); fn foo();
} }
pub fn doit() { pub fn doit() {
unsafe { foo(); } unsafe {
foo();
}
} }

View file

@ -1,6 +1,6 @@
#![crate_type = "dylib"] #![crate_type = "dylib"]
#[link(name = "foo", kind = "static")] #[link(name = "foo", kind = "static")]
extern { extern "C" {
pub fn foo(); pub fn foo();
} }

View file

@ -1,11 +1,11 @@
#[link(name = "test", kind = "static")] #[link(name = "test", kind = "static")]
extern { extern "C" {
fn slice_len(s: &[u8]) -> usize; fn slice_len(s: &[u8]) -> usize;
fn slice_elem(s: &[u8], idx: usize) -> u8; fn slice_elem(s: &[u8], idx: usize) -> u8;
} }
fn main() { fn main() {
let data = [1,2,3,4,5]; let data = [1, 2, 3, 4, 5];
unsafe { unsafe {
assert_eq!(data.len(), slice_len(&data) as usize); assert_eq!(data.len(), slice_len(&data) as usize);

View file

@ -1,6 +1,6 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
#[link(name = "a", kind = "static")] #[link(name = "a", kind = "static")]
extern { extern "C" {
pub fn a(); pub fn a();
} }

View file

@ -1,11 +1,12 @@
extern crate a; extern crate a;
#[link(name = "b", kind = "static")] #[link(name = "b", kind = "static")]
extern { extern "C" {
pub fn b(); pub fn b();
} }
fn main() { fn main() {
unsafe { b(); } unsafe {
b();
}
} }

View file

@ -3,6 +3,6 @@
#[link(name = "return1", cfg(foo))] #[link(name = "return1", cfg(foo))]
#[link(name = "return3", kind = "static", cfg(bar))] #[link(name = "return3", kind = "static", cfg(bar))]
extern { extern "C" {
pub fn my_function() -> i32; pub fn my_function() -> i32;
} }

View file

@ -3,6 +3,6 @@
#[link(name = "return1", cfg(foo))] #[link(name = "return1", cfg(foo))]
#[link(name = "return2", cfg(bar))] #[link(name = "return2", cfg(bar))]
extern { extern "C" {
pub fn my_function() -> i32; pub fn my_function() -> i32;
} }

View file

@ -2,7 +2,7 @@
#[link(name = "return1", cfg(foo))] #[link(name = "return1", cfg(foo))]
#[link(name = "return2", cfg(bar))] #[link(name = "return2", cfg(bar))]
extern { extern "C" {
fn my_function() -> i32; fn my_function() -> i32;
} }

View file

@ -2,15 +2,13 @@
extern crate libc; extern crate libc;
#[link(name="foo", kind = "static")] #[link(name = "foo", kind = "static")]
extern { extern "C" {
fn should_return_one() -> libc::c_int; fn should_return_one() -> libc::c_int;
} }
fn main() { fn main() {
let result = unsafe { let result = unsafe { should_return_one() };
should_return_one()
};
if result != 1 { if result != 1 {
std::process::exit(255); std::process::exit(255);

View file

@ -5,7 +5,7 @@
static BAZ: i32 = 21; static BAZ: i32 = 21;
#[link(name = "foo", kind = "static")] #[link(name = "foo", kind = "static")]
extern { extern "C" {
fn what() -> i32; fn what() -> i32;
} }

View file

@ -25,7 +25,7 @@ fn write_test_case(file: &Path, n: usize) -> HashSet<String> {
writeln!(f, "#[link(name = \"S{}{}S\")]", prefix, i).unwrap(); writeln!(f, "#[link(name = \"S{}{}S\")]", prefix, i).unwrap();
libs.insert(format!("{}{}", prefix, i)); libs.insert(format!("{}{}", prefix, i));
} }
writeln!(f, "extern {{}}\nfn main() {{}}").unwrap(); writeln!(f, "extern \"C\" {{}}\nfn main() {{}}").unwrap();
f.into_inner().unwrap(); f.into_inner().unwrap();
libs libs

View file

@ -1,6 +1,6 @@
#[link(name = "foo", kind = "static")] #[link(name = "foo", kind = "static")]
extern { extern "C" {
fn test_start(f: extern fn()); fn test_start(f: extern "C" fn());
fn test_end(); fn test_end();
} }
@ -13,11 +13,10 @@ fn main() {
struct A; struct A;
impl Drop for A { impl Drop for A {
fn drop(&mut self) { fn drop(&mut self) {}
}
} }
extern fn test_middle() { extern "C" fn test_middle() {
let _a = A; let _a = A;
foo(); foo();
} }

View file

@ -1,7 +1,7 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
#[link(name = "foo", kind = "static")] #[link(name = "foo", kind = "static")]
extern { extern "C" {
fn foo() -> i32; fn foo() -> i32;
} }

View file

@ -3,7 +3,7 @@
extern crate lib1; extern crate lib1;
#[link(name = "bar", kind = "static")] #[link(name = "bar", kind = "static")]
extern { extern "C" {
fn foo() -> i32; fn foo() -> i32;
} }

View file

@ -1,9 +1,11 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
extern { extern "C" {
fn bar(); fn bar();
} }
pub fn foo() { pub fn foo() {
unsafe { bar(); } unsafe {
bar();
}
} }

View file

@ -1,7 +1,7 @@
#[link(name = "foo")] // linker should drop this library, no symbols used #[link(name = "foo")] // linker should drop this library, no symbols used
#[link(name = "bar")] // symbol comes from this library #[link(name = "bar")] // symbol comes from this library
#[link(name = "foo")] // now linker picks up `foo` b/c `bar` library needs it #[link(name = "foo")] // now linker picks up `foo` b/c `bar` library needs it
extern { extern "C" {
fn bar(); fn bar();
} }

View file

@ -1,4 +1,4 @@
extern { extern "C" {
fn overflow(); fn overflow();
} }

View file

@ -1,4 +1,4 @@
extern { extern "C" {
fn overflow(); fn overflow();
} }

View file

@ -1,5 +1,5 @@
#[link(name = "library")] #[link(name = "library")]
extern { extern "C" {
fn overflow(); fn overflow();
} }

View file

@ -1,4 +1,4 @@
#![ crate_name = "test" ] #![crate_name = "test"]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(rustc_private)] #![feature(rustc_private)]
@ -9,11 +9,10 @@ extern crate krate2;
extern crate krate2 as krate3; extern crate krate2 as krate3;
use rustc_graphviz::RenderOption; use rustc_graphviz::RenderOption;
use std::collections::{HashMap,HashSet};
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::io::Write; use std::io::Write;
use sub::sub2 as msalias; use sub::sub2 as msalias;
use sub::sub2; use sub::sub2;
use sub::sub2::nested_struct as sub_struct; use sub::sub2::nested_struct as sub_struct;
@ -30,7 +29,7 @@ static bob: Option<graphviz::RenderOption> = None;
// buglink test - see issue #1337. // buglink test - see issue #1337.
fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) { fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) {
let s = sub_struct{ field2: 45u32, }; let s = sub_struct { field2: 45u32 };
// import tests // import tests
fn foo(x: &Write) {} fn foo(x: &Write) {}
@ -80,7 +79,7 @@ mod sub {
pub enum nested_enum { pub enum nested_enum {
Nest2 = 2, Nest2 = 2,
Nest3 = 3 Nest3 = 3,
} }
} }
} }
@ -101,7 +100,9 @@ struct some_fields {
type SF = some_fields; type SF = some_fields;
trait SuperTrait { trait SuperTrait {
fn qux(&self) { panic!(); } fn qux(&self) {
panic!();
}
} }
trait SomeTrait: SuperTrait { trait SomeTrait: SuperTrait {
@ -136,8 +137,7 @@ impl SomeTrait for some_fields {
} }
} }
impl SuperTrait for some_fields { impl SuperTrait for some_fields {}
}
impl SubTrait for some_fields {} impl SubTrait for some_fields {}
@ -150,17 +150,14 @@ impl some_fields {
42 42
} }
fn align_to<T>(&mut self) { fn align_to<T>(&mut self) {}
}
fn test(&mut self) { fn test(&mut self) {
self.align_to::<bool>(); self.align_to::<bool>();
} }
} }
impl SuperTrait for nofields { impl SuperTrait for nofields {}
}
impl SomeTrait for nofields { impl SomeTrait for nofields {
fn Method(&self, x: u32) -> u32 { fn Method(&self, x: u32) -> u32 {
self.Method(x); self.Method(x);
@ -186,59 +183,70 @@ enum SomeEnum<'a> {
Ints(isize, isize), Ints(isize, isize),
Floats(f64, f64), Floats(f64, f64),
Strings(&'a str, &'a str, &'a str), Strings(&'a str, &'a str, &'a str),
MyTypes(MyType, MyType) MyTypes(MyType, MyType),
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
enum SomeOtherEnum { enum SomeOtherEnum {
SomeConst1, SomeConst1,
SomeConst2, SomeConst2,
SomeConst3 SomeConst3,
} }
enum SomeStructEnum { enum SomeStructEnum {
EnumStruct{a:isize, b:isize}, EnumStruct { a: isize, b: isize },
EnumStruct2{f1:MyType, f2:MyType}, EnumStruct2 { f1: MyType, f2: MyType },
EnumStruct3{f1:MyType, f2:MyType, f3:SomeEnum<'static>} EnumStruct3 { f1: MyType, f2: MyType, f3: SomeEnum<'static> },
} }
fn matchSomeEnum(val: SomeEnum) { fn matchSomeEnum(val: SomeEnum) {
match val { match val {
SomeEnum::Ints(int1, int2) => { println(&(int1+int2).to_string()); } SomeEnum::Ints(int1, int2) => {
SomeEnum::Floats(float1, float2) => { println(&(float2*float1).to_string()); } println(&(int1 + int2).to_string());
SomeEnum::Strings(.., s3) => { println(s3); } }
SomeEnum::MyTypes(mt1, mt2) => { println(&(mt1.field1 - mt2.field1).to_string()); } SomeEnum::Floats(float1, float2) => {
println(&(float2 * float1).to_string());
}
SomeEnum::Strings(.., s3) => {
println(s3);
}
SomeEnum::MyTypes(mt1, mt2) => {
println(&(mt1.field1 - mt2.field1).to_string());
}
} }
} }
fn matchSomeStructEnum(se: SomeStructEnum) { fn matchSomeStructEnum(se: SomeStructEnum) {
match se { match se {
SomeStructEnum::EnumStruct{a:a, ..} => println(&a.to_string()), SomeStructEnum::EnumStruct { a: a, .. } => println(&a.to_string()),
SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(&f_2.field1.to_string()), SomeStructEnum::EnumStruct2 { f1: f1, f2: f_2 } => println(&f_2.field1.to_string()),
SomeStructEnum::EnumStruct3{f1, ..} => println(&f1.field1.to_string()), SomeStructEnum::EnumStruct3 { f1, .. } => println(&f1.field1.to_string()),
} }
} }
fn matchSomeStructEnum2(se: SomeStructEnum) { fn matchSomeStructEnum2(se: SomeStructEnum) {
use SomeStructEnum::*; use SomeStructEnum::*;
match se { match se {
EnumStruct{a: ref aaa, ..} => println(&aaa.to_string()), EnumStruct { a: ref aaa, .. } => println(&aaa.to_string()),
EnumStruct2{f1, f2: f2} => println(&f1.field1.to_string()), EnumStruct2 { f1, f2: f2 } => println(&f1.field1.to_string()),
EnumStruct3{f1, f3: SomeEnum::Ints(..), f2} => println(&f1.field1.to_string()), EnumStruct3 { f1, f3: SomeEnum::Ints(..), f2 } => println(&f1.field1.to_string()),
_ => {}, _ => {}
} }
} }
fn matchSomeOtherEnum(val: SomeOtherEnum) { fn matchSomeOtherEnum(val: SomeOtherEnum) {
use SomeOtherEnum::{SomeConst2, SomeConst3}; use SomeOtherEnum::{SomeConst2, SomeConst3};
match val { match val {
SomeOtherEnum::SomeConst1 => { println("I'm const1."); } SomeOtherEnum::SomeConst1 => {
SomeConst2 | SomeConst3 => { println("I'm const2 or const3."); } println("I'm const1.");
}
SomeConst2 | SomeConst3 => {
println("I'm const2 or const3.");
}
} }
} }
fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) { fn hello<X: SomeTrait>((z, a): (u32, String), ex: X) {
SameDir2::hello(43); SameDir2::hello(43);
println(&yy.to_string()); println(&yy.to_string());
@ -253,8 +261,8 @@ fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) {
let x = 32.0f32; let x = 32.0f32;
let _ = (x + ((x * x) + 1.0).sqrt()).ln(); let _ = (x + ((x * x) + 1.0).sqrt()).ln();
let s: Box<SomeTrait> = box some_fields {field1: 43}; let s: Box<SomeTrait> = box some_fields { field1: 43 };
let s2: Box<some_fields> = box some_fields {field1: 43}; let s2: Box<some_fields> = box some_fields { field1: 43 };
let s3 = box nofields; let s3 = box nofields;
s.Method(43); s.Method(43);
@ -307,8 +315,9 @@ mod macro_use_test {
} }
} }
fn main() { // foo fn main() {
let s = box some_fields {field1: 43}; // foo
let s = box some_fields { field1: 43 };
hello((43, "a".to_string()), *s); hello((43, "a".to_string()), *s);
sub::sub2::hello(); sub::sub2::hello();
sub2::sub3::hello(); sub2::sub3::hello();
@ -329,26 +338,24 @@ fn main() { // foo
let vs = variable_str!(32); let vs = variable_str!(32);
let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new()); let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
let _ = blah { let _ = blah { used_link_args: RefCell::new([]) };
used_link_args: RefCell::new([]),
};
let s1 = nofields; let s1 = nofields;
let s2 = SF { field1: 55}; let s2 = SF { field1: 55 };
let s3: some_fields = some_fields{ field1: 55}; let s3: some_fields = some_fields { field1: 55 };
let s4: msalias::nested_struct = sub::sub2::nested_struct{ field2: 55}; let s4: msalias::nested_struct = sub::sub2::nested_struct { field2: 55 };
let s4: msalias::nested_struct = sub2::nested_struct{ field2: 55}; let s4: msalias::nested_struct = sub2::nested_struct { field2: 55 };
println(&s2.field1.to_string()); println(&s2.field1.to_string());
let s5: MyType = box some_fields{ field1: 55}; let s5: MyType = box some_fields { field1: 55 };
let s = SameDir::SameStruct{name: "Bob".to_string()}; let s = SameDir::SameStruct { name: "Bob".to_string() };
let s = SubDir::SubStruct{name:"Bob".to_string()}; let s = SubDir::SubStruct { name: "Bob".to_string() };
let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5); let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5);
let s7: SomeEnum = SomeEnum::Strings("one", "two", "three"); let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
matchSomeEnum(s6); matchSomeEnum(s6);
matchSomeEnum(s7); matchSomeEnum(s7);
let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2; let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
matchSomeOtherEnum(s8); matchSomeOtherEnum(s8);
let s9: SomeStructEnum = SomeStructEnum::EnumStruct2{ f1: box some_fields{ field1:10 }, let s9: SomeStructEnum =
f2: box s2 }; SomeStructEnum::EnumStruct2 { f1: box some_fields { field1: 10 }, f2: box s2 };
matchSomeStructEnum(s9); matchSomeStructEnum(s9);
for x in &vec![1, 2, 3] { for x in &vec![1, 2, 3] {
@ -409,8 +416,7 @@ impl<'a> Pattern<'a> for CharEqPattern {
struct CharSearcher<'a>(<CharEqPattern as Pattern<'a>>::Searcher); struct CharSearcher<'a>(<CharEqPattern as Pattern<'a>>::Searcher);
pub trait Error { pub trait Error {}
}
impl Error + 'static { impl Error + 'static {
pub fn is<T: Error + 'static>(&self) -> bool { pub fn is<T: Error + 'static>(&self) -> bool {
@ -437,7 +443,7 @@ fn test_format_args() {
print!("x is {}, y is {1}, name is {n}", x, y, n = name); print!("x is {}, y is {1}, name is {n}", x, y, n = name);
} }
extern { extern "C" {
static EXTERN_FOO: u8; static EXTERN_FOO: u8;
fn extern_foo(a: u8, b: i32) -> String; fn extern_foo(a: u8, b: i32) -> String;
} }

View file

@ -2,7 +2,7 @@
#![feature(static_nobundle)] #![feature(static_nobundle)]
#[link(name = "aaa", kind = "static-nobundle")] #[link(name = "aaa", kind = "static-nobundle")]
extern { extern "C" {
pub fn native_func(); pub fn native_func();
} }

View file

@ -1,6 +1,6 @@
#![crate_type = "staticlib"] #![crate_type = "staticlib"]
#[link(name = "foo", kind = "static")] #[link(name = "foo", kind = "static")]
extern {} extern "C" {}
fn main() {} fn main() {}

View file

@ -1,19 +1,21 @@
#![feature(lang_items, no_core, auto_traits)] #![feature(lang_items, no_core, auto_traits)]
#![no_core] #![no_core]
#[lang="copy"] #[lang = "copy"]
trait Copy { } trait Copy {}
#[lang="sized"] #[lang = "sized"]
trait Sized { } trait Sized {}
#[lang = "freeze"] #[lang = "freeze"]
auto trait Freeze {} auto trait Freeze {}
#[lang="start"] #[lang = "start"]
fn start(_main: *const u8, _argc: isize, _argv: *const *const u8) -> isize { 0 } fn start(_main: *const u8, _argc: isize, _argv: *const *const u8) -> isize {
0
}
extern { extern "C" {
fn _foo() -> [u8; 16]; fn _foo() -> [u8; 16];
} }

View file

@ -3,7 +3,9 @@
// For linking libstdc++ on MinGW // For linking libstdc++ on MinGW
#![cfg_attr(all(windows, target_env = "gnu"), feature(static_nobundle))] #![cfg_attr(all(windows, target_env = "gnu"), feature(static_nobundle))]
extern { fn get() -> u32; } extern "C" {
fn get() -> u32;
}
fn main() { fn main() {
let i = unsafe { get() }; let i = unsafe { get() };

View file

@ -4,13 +4,13 @@
extern crate foo; extern crate foo;
#[link(wasm_import_module = "./me")] #[link(wasm_import_module = "./me")]
extern { extern "C" {
#[link_name = "me_in_dep"] #[link_name = "me_in_dep"]
fn dep(); fn dep();
} }
#[no_mangle] #[no_mangle]
pub extern fn foo() { pub extern "C" fn foo() {
unsafe { unsafe {
foo::dep(); foo::dep();
dep(); dep();

View file

@ -2,6 +2,6 @@
#![deny(warnings)] #![deny(warnings)]
#[link(wasm_import_module = "./dep")] #[link(wasm_import_module = "./dep")]
extern { extern "C" {
pub fn dep(); pub fn dep();
} }

View file

@ -6,13 +6,15 @@ extern crate libc;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
#[link(name = "CoreFoundation", kind = "framework")] #[link(name = "CoreFoundation", kind = "framework")]
extern { extern "C" {
fn CFRunLoopGetTypeID() -> libc::c_ulong; fn CFRunLoopGetTypeID() -> libc::c_ulong;
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
pub fn main() { pub fn main() {
unsafe { CFRunLoopGetTypeID(); } unsafe {
CFRunLoopGetTypeID();
}
} }
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]

View file

@ -5,7 +5,7 @@ pub trait Foo {
} }
#[doc(alias = "foo")] //~ ERROR #[doc(alias = "foo")] //~ ERROR
extern {} extern "C" {}
#[doc(alias = "bar")] //~ ERROR #[doc(alias = "bar")] //~ ERROR
impl Bar { impl Bar {
@ -17,5 +17,7 @@ impl Bar {
impl Foo for Bar { impl Foo for Bar {
#[doc(alias = "assoc")] //~ ERROR #[doc(alias = "assoc")] //~ ERROR
type X = i32; type X = i32;
fn foo() -> Self::X { 0 } fn foo() -> Self::X {
0
}
} }

View file

@ -45,6 +45,6 @@ macro_rules! some_macro {
() => {}; () => {};
} }
extern { extern "C" {
pub type ExternType; pub type ExternType;
} }

View file

@ -1,3 +1,3 @@
extern { extern "C" {
pub fn extern_c_fn(); pub fn extern_c_fn();
} }

View file

@ -1,7 +1,7 @@
#![feature(extern_types)] #![feature(extern_types)]
mod sub { mod sub {
extern { extern "C" {
/// Another extern type. /// Another extern type.
pub type C2; pub type C2;
pub fn f2(); pub fn f2();
@ -10,7 +10,7 @@ mod sub {
} }
pub mod sub2 { pub mod sub2 {
extern { extern "C" {
// @has foreigntype_reexport/sub2/foreigntype.C.html // @has foreigntype_reexport/sub2/foreigntype.C.html
pub type C; pub type C;
// @has foreigntype_reexport/sub2/fn.f.html // @has foreigntype_reexport/sub2/fn.f.html
@ -21,7 +21,7 @@ pub mod sub2 {
} }
mod sub3 { mod sub3 {
extern { extern "C" {
pub type C4; pub type C4;
pub fn f4(); pub fn f4();
pub static K4: usize; pub static K4: usize;
@ -35,7 +35,7 @@ mod sub3 {
// @has foreigntype_reexport/index.html '//a[@class="foreigntype"]' 'C2' // @has foreigntype_reexport/index.html '//a[@class="foreigntype"]' 'C2'
// @has foreigntype_reexport/index.html '//a[@class="fn"]' 'f2' // @has foreigntype_reexport/index.html '//a[@class="fn"]' 'f2'
// @has foreigntype_reexport/index.html '//a[@class="static"]' 'K2' // @has foreigntype_reexport/index.html '//a[@class="static"]' 'K2'
pub use self::sub::{C2, f2, K as K2}; pub use self::sub::{f2, C2, K as K2};
// @has foreigntype_reexport/index.html '//a[@class="foreigntype"]' 'C' // @has foreigntype_reexport/index.html '//a[@class="foreigntype"]' 'C'
// @has foreigntype_reexport/index.html '//a[@class="fn"]' 'f' // @has foreigntype_reexport/index.html '//a[@class="fn"]' 'f'
@ -43,7 +43,7 @@ pub use self::sub::{C2, f2, K as K2};
// @has foreigntype_reexport/index.html '//code' 'pub use self::sub2::C as C3;' // @has foreigntype_reexport/index.html '//code' 'pub use self::sub2::C as C3;'
// @has foreigntype_reexport/index.html '//code' 'pub use self::sub2::f as f3;' // @has foreigntype_reexport/index.html '//code' 'pub use self::sub2::f as f3;'
// @has foreigntype_reexport/index.html '//code' 'pub use self::sub2::K3;' // @has foreigntype_reexport/index.html '//code' 'pub use self::sub2::K3;'
pub use self::sub2::{C as C3, f as f3, K3}; pub use self::sub2::{f as f3, C as C3, K3};
// @has foreigntype_reexport/foreigntype.C4.html // @has foreigntype_reexport/foreigntype.C4.html
// @has foreigntype_reexport/fn.f4.html // @has foreigntype_reexport/fn.f4.html

View file

@ -1,6 +1,6 @@
#![feature(extern_types)] #![feature(extern_types)]
extern { extern "C" {
// @has foreigntype/foreigntype.ExtType.html // @has foreigntype/foreigntype.ExtType.html
pub type ExtType; pub type ExtType;
} }

View file

@ -3,7 +3,7 @@
#![crate_name = "foo"] #![crate_name = "foo"]
mod mod1 { mod mod1 {
extern { extern "C" {
pub fn public_fn(); pub fn public_fn();
fn private_fn(); fn private_fn();
} }

View file

@ -1,7 +1,7 @@
#![crate_name = "foo"] #![crate_name = "foo"]
mod mod1 { mod mod1 {
extern { extern "C" {
pub fn public_fn(); pub fn public_fn();
fn private_fn(); fn private_fn();
} }

View file

@ -1,4 +1,4 @@
extern { extern "C" {
// @has issue_22038/fn.foo1.html \ // @has issue_22038/fn.foo1.html \
// '//*[@class="rust fn"]' 'pub unsafe extern "C" fn foo1()' // '//*[@class="rust fn"]' 'pub unsafe extern "C" fn foo1()'
pub fn foo1(); pub fn foo1();
@ -12,7 +12,7 @@ extern "system" {
// @has issue_22038/fn.bar.html \ // @has issue_22038/fn.bar.html \
// '//*[@class="rust fn"]' 'pub extern "C" fn bar()' // '//*[@class="rust fn"]' 'pub extern "C" fn bar()'
pub extern fn bar() {} pub extern "C" fn bar() {}
// @has issue_22038/fn.baz.html \ // @has issue_22038/fn.baz.html \
// '//*[@class="rust fn"]' 'pub extern "system" fn baz()' // '//*[@class="rust fn"]' 'pub extern "system" fn baz()'

View file

@ -7,7 +7,7 @@
// correctly, then linking will fail. // correctly, then linking will fail.
/// ``` /// ```
/// extern { /// extern "C" {
/// fn __sanitizer_print_stack_trace(); /// fn __sanitizer_print_stack_trace();
/// } /// }
/// ///

View file

@ -7,7 +7,7 @@ pub mod foo_mod {
pub struct __Thing {} pub struct __Thing {}
} }
extern { extern "C" {
// @matches 'foo/fn.foo_ffn.html' '//h1' 'Function foo::foo_ffn' // @matches 'foo/fn.foo_ffn.html' '//h1' 'Function foo::foo_ffn'
pub fn foo_ffn(); pub fn foo_ffn();
} }
@ -30,7 +30,7 @@ pub type FooType = FooStruct;
// @matches 'foo/macro.foo_macro.html' '//h1' 'Macro foo::foo_macro' // @matches 'foo/macro.foo_macro.html' '//h1' 'Macro foo::foo_macro'
#[macro_export] #[macro_export]
macro_rules! foo_macro { macro_rules! foo_macro {
() => (); () => {};
} }
// @matches 'foo/primitive.bool.html' '//h1' 'Primitive Type bool' // @matches 'foo/primitive.bool.html' '//h1' 'Primitive Type bool'
@ -40,7 +40,7 @@ mod bool {}
// @matches 'foo/static.FOO_STATIC.html' '//h1' 'Static foo::FOO_STATIC' // @matches 'foo/static.FOO_STATIC.html' '//h1' 'Static foo::FOO_STATIC'
pub static FOO_STATIC: FooStruct = FooStruct; pub static FOO_STATIC: FooStruct = FooStruct;
extern { extern "C" {
// @matches 'foo/static.FOO_FSTATIC.html' '//h1' 'Static foo::FOO_FSTATIC' // @matches 'foo/static.FOO_FSTATIC.html' '//h1' 'Static foo::FOO_FSTATIC'
pub static FOO_FSTATIC: FooStruct; pub static FOO_FSTATIC: FooStruct;
} }

View file

@ -9,7 +9,7 @@ use std::path::PathBuf;
fn switch_stdout_to(file: File) { fn switch_stdout_to(file: File) {
use std::os::unix::prelude::*; use std::os::unix::prelude::*;
extern { extern "C" {
fn dup2(old: i32, new: i32) -> i32; fn dup2(old: i32, new: i32) -> i32;
} }
@ -29,8 +29,7 @@ fn switch_stdout_to(file: File) {
const STD_OUTPUT_HANDLE: u32 = (-11i32) as u32; const STD_OUTPUT_HANDLE: u32 = (-11i32) as u32;
unsafe { unsafe {
let rc = SetStdHandle(STD_OUTPUT_HANDLE, let rc = SetStdHandle(STD_OUTPUT_HANDLE, file.into_raw_handle() as *mut _);
file.into_raw_handle() as *mut _);
assert!(rc != 0); assert!(rc != 0);
} }
} }

View file

@ -7,7 +7,7 @@
extern crate libc; extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
fn rust_get_test_int() -> libc::intptr_t; fn rust_get_test_int() -> libc::intptr_t;
} }

View file

@ -1,9 +1,9 @@
#![crate_name="anonexternmod"] #![crate_name = "anonexternmod"]
#![feature(rustc_private)] #![feature(rustc_private)]
extern crate libc; extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t; pub fn rust_get_test_int() -> libc::intptr_t;
} }

View file

@ -1,12 +1,11 @@
#![crate_name="foreign_lib"] #![crate_name = "foreign_lib"]
#![feature(rustc_private)] #![feature(rustc_private)]
pub mod rustrt { pub mod rustrt {
extern crate libc; extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t; pub fn rust_get_test_int() -> libc::intptr_t;
} }
} }
@ -14,7 +13,7 @@ pub mod rustrt {
pub mod rustrt2 { pub mod rustrt2 {
extern crate libc; extern crate libc;
extern { extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t; pub fn rust_get_test_int() -> libc::intptr_t;
} }
} }
@ -24,7 +23,7 @@ pub mod rustrt3 {
// Ensures that we don't ICE or trigger LLVM asserts when // Ensures that we don't ICE or trigger LLVM asserts when
// importing the same symbol under different types. // importing the same symbol under different types.
// See https://github.com/rust-lang/rust/issues/32740. // See https://github.com/rust-lang/rust/issues/32740.
extern { extern "C" {
pub fn rust_get_test_int() -> *const u8; pub fn rust_get_test_int() -> *const u8;
} }
} }

View file

@ -8,7 +8,7 @@ mod rustrt {
extern crate libc; extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t; pub fn rust_get_test_int() -> libc::intptr_t;
} }
} }

View file

@ -2,7 +2,7 @@
// ignore-wasm32-bare no libc to test ffi with // ignore-wasm32-bare no libc to test ffi with
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
fn rust_int8_to_int32(_: i8) -> i32; fn rust_int8_to_int32(_: i8) -> i32;
} }

View file

@ -1,9 +1,9 @@
#![crate_name="anonexternmod"] #![crate_name = "anonexternmod"]
#![feature(rustc_private)] #![feature(rustc_private)]
extern crate libc; extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t; pub fn rust_get_test_int() -> libc::intptr_t;
} }

View file

@ -1,9 +1,9 @@
#![crate_name="anonexternmod"] #![crate_name = "anonexternmod"]
#![feature(rustc_private)] #![feature(rustc_private)]
extern crate libc; extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t; pub fn rust_get_test_int() -> libc::intptr_t;
} }

View file

@ -1,4 +1,4 @@
#![crate_name="externcallback"] #![crate_name = "externcallback"]
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(rustc_private)] #![feature(rustc_private)]
@ -8,10 +8,11 @@ pub mod rustrt {
extern crate libc; extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, pub fn rust_dbg_call(
data: libc::uintptr_t) cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
-> libc::uintptr_t; data: libc::uintptr_t,
) -> libc::uintptr_t;
} }
} }
@ -22,10 +23,6 @@ pub fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
} }
} }
pub extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { pub extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
if data == 1 { if data == 1 { data } else { fact(data - 1) * data }
data
} else {
fact(data - 1) * data
}
} }

View file

@ -10,19 +10,16 @@ mod rustrt {
extern crate libc; extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, pub fn rust_dbg_call(
data: libc::uintptr_t) cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
-> libc::uintptr_t; data: libc::uintptr_t,
) -> libc::uintptr_t;
} }
} }
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
if data == 1 { if data == 1 { data } else { count(data - 1) + 1 }
data
} else {
count(data - 1) + 1
}
} }
fn count(n: libc::uintptr_t) -> libc::uintptr_t { fn count(n: libc::uintptr_t) -> libc::uintptr_t {

View file

@ -1,7 +1,6 @@
// run-pass // run-pass
#![allow(unused_must_use)] #![allow(unused_must_use)]
// ignore-emscripten no threads support // ignore-emscripten no threads support
#![feature(rustc_private)] #![feature(rustc_private)]
extern crate libc; extern crate libc;
@ -11,19 +10,16 @@ mod rustrt {
extern crate libc; extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, pub fn rust_dbg_call(
data: libc::uintptr_t) cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
-> libc::uintptr_t; data: libc::uintptr_t,
) -> libc::uintptr_t;
} }
} }
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
if data == 1 { if data == 1 { data } else { count(data - 1) + 1 }
data
} else {
count(data - 1) + 1
}
} }
fn count(n: libc::uintptr_t) -> libc::uintptr_t { fn count(n: libc::uintptr_t) -> libc::uintptr_t {
@ -36,9 +32,10 @@ fn count(n: libc::uintptr_t) -> libc::uintptr_t {
pub fn main() { pub fn main() {
// Make sure we're on a thread with small Rust stacks (main currently // Make sure we're on a thread with small Rust stacks (main currently
// has a large stack) // has a large stack)
thread::spawn(move|| { thread::spawn(move || {
let result = count(1000); let result = count(1000);
println!("result = {}", result); println!("result = {}", result);
assert_eq!(result, 1000); assert_eq!(result, 1000);
}).join(); })
.join();
} }

View file

@ -9,19 +9,16 @@ mod rustrt {
extern crate libc; extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, pub fn rust_dbg_call(
data: libc::uintptr_t) cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
-> libc::uintptr_t; data: libc::uintptr_t,
) -> libc::uintptr_t;
} }
} }
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
if data == 1 { if data == 1 { data } else { fact(data - 1) * data }
data
} else {
fact(data - 1) * data
}
} }
fn fact(n: libc::uintptr_t) -> libc::uintptr_t { fn fact(n: libc::uintptr_t) -> libc::uintptr_t {

View file

@ -5,7 +5,6 @@
// directions // directions
// ignore-emscripten no threads support // ignore-emscripten no threads support
#![feature(rustc_private)] #![feature(rustc_private)]
extern crate libc; extern crate libc;
@ -15,19 +14,16 @@ mod rustrt {
extern crate libc; extern crate libc;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, pub fn rust_dbg_call(
data: libc::uintptr_t) cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
-> libc::uintptr_t; data: libc::uintptr_t,
) -> libc::uintptr_t;
} }
} }
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
if data == 1 { if data == 1 { data } else { count(data - 1) + count(data - 1) }
data
} else {
count(data - 1) + count(data - 1)
}
} }
fn count(n: libc::uintptr_t) -> libc::uintptr_t { fn count(n: libc::uintptr_t) -> libc::uintptr_t {
@ -40,9 +36,10 @@ fn count(n: libc::uintptr_t) -> libc::uintptr_t {
pub fn main() { pub fn main() {
// Make sure we're on a thread with small Rust stacks (main currently // Make sure we're on a thread with small Rust stacks (main currently
// has a large stack) // has a large stack)
thread::spawn(move|| { thread::spawn(move || {
let result = count(12); let result = count(12);
println!("result = {}", result); println!("result = {}", result);
assert_eq!(result, 2048); assert_eq!(result, 2048);
}).join(); })
.join();
} }

View file

@ -8,17 +8,18 @@
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(Copy, Clone, PartialEq, Debug)]
pub struct TwoU16s { pub struct TwoU16s {
one: u16, two: u16 one: u16,
two: u16,
} }
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_extern_identity_TwoU16s(v: TwoU16s) -> TwoU16s; pub fn rust_dbg_extern_identity_TwoU16s(v: TwoU16s) -> TwoU16s;
} }
pub fn main() { pub fn main() {
unsafe { unsafe {
let x = TwoU16s {one: 22, two: 23}; let x = TwoU16s { one: 22, two: 23 };
let y = rust_dbg_extern_identity_TwoU16s(x); let y = rust_dbg_extern_identity_TwoU16s(x);
assert_eq!(x, y); assert_eq!(x, y);
} }

View file

@ -8,17 +8,18 @@
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(Copy, Clone, PartialEq, Debug)]
pub struct TwoU32s { pub struct TwoU32s {
one: u32, two: u32 one: u32,
two: u32,
} }
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_extern_identity_TwoU32s(v: TwoU32s) -> TwoU32s; pub fn rust_dbg_extern_identity_TwoU32s(v: TwoU32s) -> TwoU32s;
} }
pub fn main() { pub fn main() {
unsafe { unsafe {
let x = TwoU32s {one: 22, two: 23}; let x = TwoU32s { one: 22, two: 23 };
let y = rust_dbg_extern_identity_TwoU32s(x); let y = rust_dbg_extern_identity_TwoU32s(x);
assert_eq!(x, y); assert_eq!(x, y);
} }

View file

@ -8,17 +8,18 @@
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(Copy, Clone, PartialEq, Debug)]
pub struct TwoU64s { pub struct TwoU64s {
one: u64, two: u64 one: u64,
two: u64,
} }
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_extern_identity_TwoU64s(v: TwoU64s) -> TwoU64s; pub fn rust_dbg_extern_identity_TwoU64s(v: TwoU64s) -> TwoU64s;
} }
pub fn main() { pub fn main() {
unsafe { unsafe {
let x = TwoU64s {one: 22, two: 23}; let x = TwoU64s { one: 22, two: 23 };
let y = rust_dbg_extern_identity_TwoU64s(x); let y = rust_dbg_extern_identity_TwoU64s(x);
assert_eq!(x, y); assert_eq!(x, y);
} }

View file

@ -8,17 +8,18 @@
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(Copy, Clone, PartialEq, Debug)]
pub struct TwoU8s { pub struct TwoU8s {
one: u8, two: u8 one: u8,
two: u8,
} }
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_extern_identity_TwoU8s(v: TwoU8s) -> TwoU8s; pub fn rust_dbg_extern_identity_TwoU8s(v: TwoU8s) -> TwoU8s;
} }
pub fn main() { pub fn main() {
unsafe { unsafe {
let x = TwoU8s {one: 22, two: 23}; let x = TwoU8s { one: 22, two: 23 };
let y = rust_dbg_extern_identity_TwoU8s(x); let y = rust_dbg_extern_identity_TwoU8s(x);
assert_eq!(x, y); assert_eq!(x, y);
} }

View file

@ -3,9 +3,8 @@
// Test a function that takes/returns a u8. // Test a function that takes/returns a u8.
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_extern_identity_u8(v: u8) -> u8; pub fn rust_dbg_extern_identity_u8(v: u8) -> u8;
} }

View file

@ -2,7 +2,7 @@
// ignore-wasm32-bare no libc for ffi testing // ignore-wasm32-bare no libc for ffi testing
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_extern_identity_double(v: f64) -> f64; pub fn rust_dbg_extern_identity_double(v: f64) -> f64;
} }

View file

@ -27,7 +27,7 @@ struct ManyInts {
struct Empty; struct Empty;
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
fn rust_dbg_extern_empty_struct(v1: ManyInts, e: Empty, v2: ManyInts); fn rust_dbg_extern_empty_struct(v1: ManyInts, e: Empty, v2: ManyInts);
} }
@ -39,7 +39,7 @@ pub fn main() {
arg3: 4, arg3: 4,
arg4: 5, arg4: 5,
arg5: 6, arg5: 6,
arg6: TwoU8s { one: 7, two: 8, } arg6: TwoU8s { one: 7, two: 8 },
}; };
let y = ManyInts { let y = ManyInts {
arg1: 1, arg1: 1,
@ -47,7 +47,7 @@ pub fn main() {
arg3: 3, arg3: 3,
arg4: 4, arg4: 4,
arg5: 5, arg5: 5,
arg6: TwoU8s { one: 6, two: 7, } arg6: TwoU8s { one: 6, two: 7 },
}; };
let empty = Empty; let empty = Empty;
rust_dbg_extern_empty_struct(x, empty, y); rust_dbg_extern_empty_struct(x, empty, y);

View file

@ -3,9 +3,8 @@
// Test a function that takes/returns a u32. // Test a function that takes/returns a u32.
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_extern_identity_u32(v: u32) -> u32; pub fn rust_dbg_extern_identity_u32(v: u32) -> u32;
} }

View file

@ -3,9 +3,8 @@
// Test a call to a function that takes/returns a u64. // Test a call to a function that takes/returns a u64.
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_extern_identity_u64(v: u64) -> u64; pub fn rust_dbg_extern_identity_u64(v: u64) -> u64;
} }

View file

@ -4,11 +4,12 @@
// ignore-wasm32-bare no libc to test ffi with // ignore-wasm32-bare no libc to test ffi with
pub struct TwoU16s { pub struct TwoU16s {
one: u16, two: u16 one: u16,
two: u16,
} }
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_extern_return_TwoU16s() -> TwoU16s; pub fn rust_dbg_extern_return_TwoU16s() -> TwoU16s;
} }

View file

@ -4,11 +4,12 @@
// ignore-wasm32-bare no libc to test ffi with // ignore-wasm32-bare no libc to test ffi with
pub struct TwoU32s { pub struct TwoU32s {
one: u32, two: u32 one: u32,
two: u32,
} }
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern { extern "C" {
pub fn rust_dbg_extern_return_TwoU32s() -> TwoU32s; pub fn rust_dbg_extern_return_TwoU32s() -> TwoU32s;
} }

Some files were not shown because too many files have changed in this diff Show more