mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-18 06:56:59 +00:00
Update tests for extern block linting
This commit is contained in:
parent
c4a8d7f86a
commit
8a3edb1d66
@ -3,13 +3,13 @@ You cannot use type or const parameters on foreign items.
|
||||
Example of erroneous code:
|
||||
|
||||
```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
|
||||
need:
|
||||
|
||||
```
|
||||
extern { fn some_func_i32(x: i32); }
|
||||
extern { fn some_func_i64(x: i64); }
|
||||
extern "C" { fn some_func_i32(x: i32); }
|
||||
extern "C" { fn some_func_i64(x: i64); }
|
||||
```
|
||||
|
@ -3,7 +3,7 @@ A pattern was declared as an argument in a foreign function declaration.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0130
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
|
||||
// function declarations
|
||||
}
|
||||
@ -17,7 +17,7 @@ struct SomeStruct {
|
||||
b: u32,
|
||||
}
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo(s: SomeStruct); // ok!
|
||||
}
|
||||
```
|
||||
@ -25,7 +25,7 @@ extern {
|
||||
Or:
|
||||
|
||||
```
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo(a: (u32, u32)); // ok!
|
||||
}
|
||||
```
|
||||
|
@ -3,7 +3,7 @@ A link name was given with an empty name.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0454
|
||||
#[link(name = "")] extern {}
|
||||
#[link(name = "")] extern "C" {}
|
||||
// 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:
|
||||
|
||||
```no_run
|
||||
#[link(name = "some_lib")] extern {} // ok!
|
||||
#[link(name = "some_lib")] extern "C" {} // ok!
|
||||
```
|
||||
|
@ -4,7 +4,7 @@ as frameworks are specific to that operating system.
|
||||
Erroneous code example:
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
@ -12,7 +12,7 @@ To solve this error you can use conditional compilation:
|
||||
|
||||
```
|
||||
#[cfg_attr(target="macos", link(name = "FooCoreServices", kind = "framework"))]
|
||||
extern {}
|
||||
extern "C" {}
|
||||
```
|
||||
|
||||
Learn more in the [Conditional Compilation][conditional-compilation] section
|
||||
|
@ -3,7 +3,7 @@ An unknown "kind" was specified for a link attribute.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0458
|
||||
#[link(kind = "wonderful_unicorn")] extern {}
|
||||
#[link(kind = "wonderful_unicorn")] extern "C" {}
|
||||
// error: unknown kind: `wonderful_unicorn`
|
||||
```
|
||||
|
||||
|
@ -3,7 +3,7 @@ A link was used without a name parameter.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0459
|
||||
#[link(kind = "dylib")] extern {}
|
||||
#[link(kind = "dylib")] extern "C" {}
|
||||
// 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:
|
||||
|
||||
```no_run
|
||||
#[link(kind = "dylib", name = "some_lib")] extern {} // ok!
|
||||
#[link(kind = "dylib", name = "some_lib")] extern "C" {} // ok!
|
||||
```
|
||||
|
@ -3,7 +3,7 @@ Attempted to pass an invalid type of variable into a variadic function.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0617
|
||||
extern {
|
||||
extern "C" {
|
||||
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:
|
||||
|
||||
```no_run
|
||||
# extern {
|
||||
# extern "C" {
|
||||
# fn printf(c: *const i8, ...);
|
||||
# }
|
||||
unsafe {
|
||||
|
@ -18,7 +18,7 @@ the function inside of an `extern` block.
|
||||
```
|
||||
#![feature(ffi_returns_twice)]
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
#[ffi_returns_twice] // ok!
|
||||
pub fn foo();
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ pub fn initialize_available_targets() {
|
||||
($cfg:meta, $($method:ident),*) => { {
|
||||
#[cfg($cfg)]
|
||||
fn init() {
|
||||
extern {
|
||||
extern "C" {
|
||||
$(fn $method();)*
|
||||
}
|
||||
unsafe {
|
||||
|
@ -809,7 +809,7 @@ impl AtomicBool {
|
||||
/// ```ignore (extern-declaration)
|
||||
/// # fn main() {
|
||||
/// use std::sync::atomic::AtomicBool;
|
||||
/// extern {
|
||||
/// extern "C" {
|
||||
/// fn my_atomic_op(arg: *mut bool);
|
||||
/// }
|
||||
///
|
||||
@ -2068,7 +2068,7 @@ macro_rules! atomic_int {
|
||||
/// # fn main() {
|
||||
#[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), ");")]
|
||||
/// }
|
||||
///
|
||||
|
@ -86,7 +86,7 @@ use crate::sys;
|
||||
/// use std::ffi::CString;
|
||||
/// use std::os::raw::c_char;
|
||||
///
|
||||
/// extern {
|
||||
/// extern "C" {
|
||||
/// fn my_printer(s: *const c_char);
|
||||
/// }
|
||||
///
|
||||
@ -144,7 +144,7 @@ pub struct CString {
|
||||
/// use std::ffi::CStr;
|
||||
/// use std::os::raw::c_char;
|
||||
///
|
||||
/// extern { fn my_string() -> *const c_char; }
|
||||
/// extern "C" { fn my_string() -> *const c_char; }
|
||||
///
|
||||
/// unsafe {
|
||||
/// let slice = CStr::from_ptr(my_string());
|
||||
@ -159,7 +159,7 @@ pub struct CString {
|
||||
/// use std::os::raw::c_char;
|
||||
///
|
||||
/// 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()) }
|
||||
/// }
|
||||
@ -174,7 +174,7 @@ pub struct CString {
|
||||
/// use std::ffi::CStr;
|
||||
/// 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 {
|
||||
/// unsafe {
|
||||
@ -359,7 +359,7 @@ impl CString {
|
||||
/// use std::ffi::CString;
|
||||
/// 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");
|
||||
/// unsafe {
|
||||
@ -465,7 +465,7 @@ impl CString {
|
||||
/// use std::ffi::CString;
|
||||
/// use std::os::raw::c_char;
|
||||
///
|
||||
/// extern {
|
||||
/// extern "C" {
|
||||
/// fn some_extern_function(s: *mut c_char);
|
||||
/// }
|
||||
///
|
||||
@ -1147,7 +1147,7 @@ impl CStr {
|
||||
/// use std::ffi::CStr;
|
||||
/// use std::os::raw::c_char;
|
||||
///
|
||||
/// extern {
|
||||
/// extern "C" {
|
||||
/// fn my_string() -> *const c_char;
|
||||
/// }
|
||||
///
|
||||
|
@ -15,7 +15,7 @@ usage would be:
|
||||
#![feature(link_args)]
|
||||
|
||||
#[link_args = "-foo -bar -baz"]
|
||||
extern {}
|
||||
extern "C" {}
|
||||
# fn main() {}
|
||||
```
|
||||
|
||||
|
@ -13,7 +13,7 @@ impl Drop for A {
|
||||
}
|
||||
}
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
#[link_name = "llvm.sqrt.f32"]
|
||||
fn sqrt(x: f32) -> f32;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ struct A;
|
||||
|
||||
impl Drop for A {
|
||||
fn drop(&mut self) {
|
||||
extern { fn foo(); }
|
||||
extern "C" { fn foo(); }
|
||||
unsafe { foo(); }
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
fn giraffe();
|
||||
fn turtle();
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
pub fn bar() { unsafe { foo() } }
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
// CHECK-LABEL: declare void @foo()
|
||||
// CHECK-SAME: [[ATTRS:#[0-9]+]]
|
||||
// CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readnone{{.*}} }
|
||||
|
@ -11,7 +11,7 @@ struct S {
|
||||
f3: i32,
|
||||
}
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo(s: S);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
pub fn bar() { unsafe { foo() } }
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
// CHECK-LABEL: declare void @foo()
|
||||
// CHECK-SAME: [[ATTRS:#[0-9]+]]
|
||||
// CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readonly{{.*}} }
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
pub fn bar() { unsafe { foo() } }
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
// CHECK-LABEL: declare void @foo()
|
||||
// CHECK-SAME: [[ATTRS:#[0-9]+]]
|
||||
// CHECK-DAG: attributes [[ATTRS]] = { {{.*}}returns_twice{{.*}} }
|
||||
|
@ -13,7 +13,7 @@ impl Drop for A {
|
||||
}
|
||||
}
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
#[link_name = "llvm.sqrt.f32"]
|
||||
fn sqrt(x: f32) -> f32;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#![crate_type = "lib"]
|
||||
#![feature(unwind_attributes)]
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
// CHECK: Function Attrs:{{.*}}nounwind
|
||||
// CHECK-NEXT: declare void @extern_fn
|
||||
fn extern_fn();
|
||||
|
@ -23,7 +23,6 @@
|
||||
// gdbg-check:type = struct Struct2
|
||||
// gdbr-check:type = type_names::mod1::Struct2
|
||||
|
||||
|
||||
// ENUMS
|
||||
// gdb-command:whatis simple_enum_1
|
||||
// gdbg-check:type = union Enum1
|
||||
@ -45,7 +44,6 @@
|
||||
// gdbg-check:type = union Enum3<type_names::Struct1>
|
||||
// gdbr-check:type = type_names::mod1::mod2::Enum3<type_names::Struct1>
|
||||
|
||||
|
||||
// TUPLES
|
||||
// gdb-command:whatis tuple1
|
||||
// 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)
|
||||
// gdbr-check:type = ((type_names::Struct1, type_names::mod1::mod2::Struct3), type_names::mod1::Enum2, char)
|
||||
|
||||
|
||||
// BOX
|
||||
// gdb-command:whatis box1
|
||||
// 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)
|
||||
// gdbr-check:type = (alloc::boxed::Box<type_names::mod1::mod2::Enum3<f32>>, i32)
|
||||
|
||||
|
||||
// REFERENCES
|
||||
// gdb-command:whatis ref1
|
||||
// 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)
|
||||
// gdbr-check:type = (&mut type_names::GenericStruct<type_names::mod1::Enum2, f64>, i32)
|
||||
|
||||
|
||||
// RAW POINTERS
|
||||
// gdb-command:whatis mut_ptr1
|
||||
// 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)
|
||||
// gdbr-check:type = (*const type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
|
||||
|
||||
|
||||
// VECTORS
|
||||
// gdb-command:whatis fixed_size_vec1
|
||||
// gdbg-check:type = struct ([type_names::Struct1; 3], i16)
|
||||
@ -127,7 +121,6 @@
|
||||
// gdbg-check:type = struct &[type_names::mod1::Enum2]
|
||||
// gdbr-check:type = &[type_names::mod1::Enum2]
|
||||
|
||||
|
||||
// TRAITS
|
||||
// gdb-command:whatis box_trait
|
||||
// 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>>
|
||||
// gdbr-check:type = type_names::&mut Trait2<type_names::mod1::mod2::Struct3, type_names::GenericStruct<usize, isize>>
|
||||
|
||||
|
||||
// BARE FUNCTIONS
|
||||
// gdb-command:whatis rust_fn
|
||||
// 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)
|
||||
// gdbr-check:type = (unsafe extern "C" fn(*const u8, ...) -> isize, usize)
|
||||
|
||||
|
||||
// CLOSURES
|
||||
// gdb-command:whatis closure1
|
||||
// gdbg-check:type = struct (closure, usize)
|
||||
@ -219,7 +210,7 @@ use std::marker::PhantomData;
|
||||
use std::ptr;
|
||||
|
||||
pub struct Struct1;
|
||||
struct GenericStruct<T1, T2>(PhantomData<(T1,T2)>);
|
||||
struct GenericStruct<T1, T2>(PhantomData<(T1, T2)>);
|
||||
|
||||
enum Enum1 {
|
||||
Variant1,
|
||||
@ -246,8 +237,12 @@ mod mod1 {
|
||||
}
|
||||
}
|
||||
|
||||
trait Trait1 { fn dummy(&self) { } }
|
||||
trait Trait2<T1, T2> { fn dummy(&self, _: T1, _:T2) { } }
|
||||
trait Trait1 {
|
||||
fn dummy(&self) {}
|
||||
}
|
||||
trait Trait2<T1, T2> {
|
||||
fn dummy(&self, _: T1, _: T2) {}
|
||||
}
|
||||
|
||||
impl Trait1 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>) {}
|
||||
extern "stdcall" fn extern_stdcall_fn() {}
|
||||
|
||||
fn rust_fn_with_return_value(_: f64) -> usize { 4 }
|
||||
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 rust_fn_with_return_value(_: f64) -> usize {
|
||||
4
|
||||
}
|
||||
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)]
|
||||
extern {
|
||||
fn printf(_:*const u8, ...) -> isize;
|
||||
extern "C" {
|
||||
fn printf(_: *const u8, ...) -> isize;
|
||||
}
|
||||
|
||||
// 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
|
||||
// then *contain* the type name that we want to see.
|
||||
fn main() {
|
||||
|
||||
// Structs
|
||||
let simple_struct = Struct1;
|
||||
let generic_struct1: GenericStruct<mod1::Struct2, mod1::mod2::Struct3> =
|
||||
@ -336,11 +340,11 @@ fn main() {
|
||||
let mut_ref_trait = (&mut mut_int1) as &mut Trait1;
|
||||
|
||||
let generic_box_trait = (box 0_isize) as Box<Trait2<i32, mod1::Struct2>>;
|
||||
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 generic_mut_ref_trait = (&mut generic_mut_ref_trait_impl) as
|
||||
&mut Trait2<mod1::mod2::Struct3, GenericStruct<usize, isize>>;
|
||||
let generic_mut_ref_trait = (&mut generic_mut_ref_trait_impl)
|
||||
as &mut Trait2<mod1::mod2::Struct3, GenericStruct<usize, isize>>;
|
||||
|
||||
// Bare Functions
|
||||
let rust_fn = (rust_fn, 0_usize);
|
||||
@ -364,11 +368,13 @@ fn main() {
|
||||
// how that maps to rustc's internal representation of these forms.
|
||||
// Once closures have reached their 1.0 form, the tests below should
|
||||
// probably be expanded.
|
||||
let closure1 = (|x:isize| {}, 0_usize);
|
||||
let closure2 = (|x:i8, y: f32| { (x as f32) + y }, 0_usize);
|
||||
let closure1 = (|x: isize| {}, 0_usize);
|
||||
let closure2 = (|x: i8, y: f32| (x as f32) + y, 0_usize);
|
||||
|
||||
zzz(); // #break
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
fn zzz() { () }
|
||||
fn zzz() {
|
||||
()
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ use std::ffi::CString;
|
||||
mod mlibc {
|
||||
use libc::{c_char, c_long, c_longlong};
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn atol(x: *const c_char) -> c_long;
|
||||
pub fn atoll(x: *const c_char) -> c_longlong;
|
||||
}
|
||||
@ -31,6 +31,8 @@ fn atoll(s: String) -> i64 {
|
||||
|
||||
pub fn main() {
|
||||
assert_eq!(atol("1024".to_string()) * 10, atol("10240".to_string()));
|
||||
assert_eq!((atoll("11111111111111111".to_string()) * 10),
|
||||
atoll("111111111111111110".to_string()));
|
||||
assert_eq!(
|
||||
(atoll("11111111111111111".to_string()) * 10),
|
||||
atoll("111111111111111110".to_string())
|
||||
);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#[link(name = "foo", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo();
|
||||
fn bar();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![crate_type = "dylib"]
|
||||
|
||||
#[link(name = "cfoo")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#[link(name = "cfoo")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![crate_type = "dylib"]
|
||||
|
||||
#[link(name = "cfoo", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#[link(name = "cfoo", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#[link(name = "native", kind = "static")]
|
||||
extern {}
|
||||
extern "C" {}
|
||||
|
@ -1,6 +1,10 @@
|
||||
extern { fn foo(); }
|
||||
extern "C" {
|
||||
fn foo();
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
unsafe { foo(); }
|
||||
unsafe {
|
||||
foo();
|
||||
}
|
||||
assert_eq!(7f32.powi(3), 343f32);
|
||||
}
|
||||
|
@ -1,22 +1,20 @@
|
||||
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")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn call(c: extern "C" fn(testcrate::TestStruct<i32>) -> i32) -> i32;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Let's test calling it cross crate
|
||||
let back = unsafe {
|
||||
testcrate::call(testcrate::foo::<i32>)
|
||||
};
|
||||
let back = unsafe { testcrate::call(testcrate::foo::<i32>) };
|
||||
assert_eq!(3, back);
|
||||
|
||||
// And just within this crate
|
||||
let back = unsafe {
|
||||
call(bar::<i32>)
|
||||
};
|
||||
let back = unsafe { call(bar::<i32>) };
|
||||
assert_eq!(3, back);
|
||||
}
|
||||
|
@ -3,12 +3,14 @@
|
||||
#[repr(C)]
|
||||
pub struct TestStruct<T> {
|
||||
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")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn call(c: extern "C" fn(TestStruct<i32>) -> i32) -> i32;
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
#[no_mangle]
|
||||
pub extern "C" fn foo() -> i32 { 3 }
|
||||
pub extern "C" fn foo() -> i32 {
|
||||
3
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn bar() -> i32 { 5 }
|
||||
pub extern "C" fn bar() -> i32 {
|
||||
5
|
||||
}
|
||||
|
||||
#[link(name = "test", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn add() -> i32;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ struct Rect {
|
||||
a: i32,
|
||||
b: i32,
|
||||
c: i32,
|
||||
d: i32
|
||||
d: i32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
@ -15,7 +15,7 @@ struct Rect {
|
||||
struct BiggerRect {
|
||||
s: Rect,
|
||||
a: i32,
|
||||
b: i32
|
||||
b: i32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
@ -23,7 +23,7 @@ struct BiggerRect {
|
||||
struct FloatRect {
|
||||
a: i32,
|
||||
b: i32,
|
||||
c: f64
|
||||
c: f64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
@ -33,14 +33,14 @@ struct Huge {
|
||||
b: i32,
|
||||
c: i32,
|
||||
d: i32,
|
||||
e: i32
|
||||
e: i32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[repr(C)]
|
||||
struct FloatPoint {
|
||||
x: f64,
|
||||
y: f64
|
||||
y: f64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
@ -58,13 +58,22 @@ struct IntOdd {
|
||||
}
|
||||
|
||||
#[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_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,
|
||||
f: f32, g: f64, s: Rect, t: FloatRect);
|
||||
fn byval_rect_floats(
|
||||
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);
|
||||
|
||||
@ -107,12 +116,7 @@ fn main() {
|
||||
byval_many_rect(1, 2, 3, 4, 5, 6, s);
|
||||
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_many_huge(v, v, v, v, v, v, Rect {
|
||||
a: 123,
|
||||
b: 456,
|
||||
c: 789,
|
||||
d: 420
|
||||
});
|
||||
byval_rect_with_many_huge(v, v, v, v, v, v, Rect { a: 123, b: 456, c: 789, d: 420 });
|
||||
split_rect(1, 2, s);
|
||||
split_rect_floats(1., 2., u);
|
||||
split_rect_with_floats(1, 2, 3.0, 4, 5.0, 6, s);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![feature(extern_types)]
|
||||
|
||||
#[link(name = "ctest", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
type data;
|
||||
|
||||
fn data_create(magic: u32) -> *mut data;
|
||||
|
@ -3,11 +3,11 @@
|
||||
struct Foo {
|
||||
a: i8,
|
||||
b: i16,
|
||||
c: i8
|
||||
c: i8,
|
||||
}
|
||||
|
||||
#[link(name = "test", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo(f: Foo) -> Foo;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ extern crate testcrate;
|
||||
|
||||
use std::mem;
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
fn give_back(tu: testcrate::TestUnion) -> u64;
|
||||
}
|
||||
|
||||
@ -10,14 +10,10 @@ fn main() {
|
||||
let magic: u64 = 0xDEADBEEF;
|
||||
|
||||
// Let's test calling it cross crate
|
||||
let back = unsafe {
|
||||
testcrate::give_back(mem::transmute(magic))
|
||||
};
|
||||
let back = unsafe { testcrate::give_back(mem::transmute(magic)) };
|
||||
assert_eq!(magic, back);
|
||||
|
||||
// And just within this crate
|
||||
let back = unsafe {
|
||||
give_back(mem::transmute(magic))
|
||||
};
|
||||
let back = unsafe { give_back(mem::transmute(magic)) };
|
||||
assert_eq!(magic, back);
|
||||
}
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
#[repr(C)]
|
||||
pub struct TestUnion {
|
||||
_val: u64
|
||||
_val: u64,
|
||||
}
|
||||
|
||||
#[link(name = "ctest", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn give_back(tu: TestUnion) -> u64;
|
||||
}
|
||||
|
@ -3,10 +3,12 @@
|
||||
extern crate foo;
|
||||
|
||||
#[link(name = "bar", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn bar();
|
||||
}
|
||||
|
||||
pub fn doit() {
|
||||
unsafe { bar(); }
|
||||
unsafe {
|
||||
bar();
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#[link(name = "foo", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo();
|
||||
}
|
||||
|
||||
pub fn doit() {
|
||||
unsafe { foo(); }
|
||||
unsafe {
|
||||
foo();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![crate_type = "dylib"]
|
||||
|
||||
#[link(name = "foo", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn foo();
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
#[link(name = "test", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn slice_len(s: &[u8]) -> usize;
|
||||
fn slice_elem(s: &[u8], idx: usize) -> u8;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let data = [1,2,3,4,5];
|
||||
let data = [1, 2, 3, 4, 5];
|
||||
|
||||
unsafe {
|
||||
assert_eq!(data.len(), slice_len(&data) as usize);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#[link(name = "a", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn a();
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
extern crate a;
|
||||
|
||||
#[link(name = "b", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn b();
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
unsafe { b(); }
|
||||
unsafe {
|
||||
b();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,6 @@
|
||||
|
||||
#[link(name = "return1", cfg(foo))]
|
||||
#[link(name = "return3", kind = "static", cfg(bar))]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn my_function() -> i32;
|
||||
}
|
||||
|
@ -3,6 +3,6 @@
|
||||
|
||||
#[link(name = "return1", cfg(foo))]
|
||||
#[link(name = "return2", cfg(bar))]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn my_function() -> i32;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#[link(name = "return1", cfg(foo))]
|
||||
#[link(name = "return2", cfg(bar))]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn my_function() -> i32;
|
||||
}
|
||||
|
||||
|
@ -2,15 +2,13 @@
|
||||
|
||||
extern crate libc;
|
||||
|
||||
#[link(name="foo", kind = "static")]
|
||||
extern {
|
||||
#[link(name = "foo", kind = "static")]
|
||||
extern "C" {
|
||||
fn should_return_one() -> libc::c_int;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let result = unsafe {
|
||||
should_return_one()
|
||||
};
|
||||
let result = unsafe { should_return_one() };
|
||||
|
||||
if result != 1 {
|
||||
std::process::exit(255);
|
||||
|
@ -5,7 +5,7 @@
|
||||
static BAZ: i32 = 21;
|
||||
|
||||
#[link(name = "foo", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn what() -> i32;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ fn write_test_case(file: &Path, n: usize) -> HashSet<String> {
|
||||
writeln!(f, "#[link(name = \"S{}{}S\")]", prefix, i).unwrap();
|
||||
libs.insert(format!("{}{}", prefix, i));
|
||||
}
|
||||
writeln!(f, "extern {{}}\nfn main() {{}}").unwrap();
|
||||
writeln!(f, "extern \"C\" {{}}\nfn main() {{}}").unwrap();
|
||||
f.into_inner().unwrap();
|
||||
|
||||
libs
|
||||
|
@ -1,6 +1,6 @@
|
||||
#[link(name = "foo", kind = "static")]
|
||||
extern {
|
||||
fn test_start(f: extern fn());
|
||||
extern "C" {
|
||||
fn test_start(f: extern "C" fn());
|
||||
fn test_end();
|
||||
}
|
||||
|
||||
@ -13,11 +13,10 @@ fn main() {
|
||||
struct 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;
|
||||
foo();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#[link(name = "foo", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo() -> i32;
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
extern crate lib1;
|
||||
|
||||
#[link(name = "bar", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo() -> i32;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
fn bar();
|
||||
}
|
||||
|
||||
pub fn foo() {
|
||||
unsafe { bar(); }
|
||||
unsafe {
|
||||
bar();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#[link(name = "foo")] // linker should drop this library, no symbols used
|
||||
#[link(name = "bar")] // symbol comes from this library
|
||||
#[link(name = "foo")] // now linker picks up `foo` b/c `bar` library needs it
|
||||
extern {
|
||||
extern "C" {
|
||||
fn bar();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
extern {
|
||||
extern "C" {
|
||||
fn overflow();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
extern {
|
||||
extern "C" {
|
||||
fn overflow();
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#[link(name = "library")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn overflow();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![ crate_name = "test" ]
|
||||
#![crate_name = "test"]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
@ -9,11 +9,10 @@ extern crate krate2;
|
||||
extern crate krate2 as krate3;
|
||||
|
||||
use rustc_graphviz::RenderOption;
|
||||
use std::collections::{HashMap,HashSet};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::io::Write;
|
||||
|
||||
|
||||
use sub::sub2 as msalias;
|
||||
use sub::sub2;
|
||||
use sub::sub2::nested_struct as sub_struct;
|
||||
@ -30,7 +29,7 @@ static bob: Option<graphviz::RenderOption> = None;
|
||||
// buglink test - see issue #1337.
|
||||
|
||||
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
|
||||
fn foo(x: &Write) {}
|
||||
@ -80,7 +79,7 @@ mod sub {
|
||||
|
||||
pub enum nested_enum {
|
||||
Nest2 = 2,
|
||||
Nest3 = 3
|
||||
Nest3 = 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,7 +100,9 @@ struct some_fields {
|
||||
type SF = some_fields;
|
||||
|
||||
trait SuperTrait {
|
||||
fn qux(&self) { panic!(); }
|
||||
fn qux(&self) {
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
|
||||
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 {}
|
||||
|
||||
@ -150,17 +150,14 @@ impl some_fields {
|
||||
42
|
||||
}
|
||||
|
||||
fn align_to<T>(&mut self) {
|
||||
|
||||
}
|
||||
fn align_to<T>(&mut self) {}
|
||||
|
||||
fn test(&mut self) {
|
||||
self.align_to::<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
impl SuperTrait for nofields {
|
||||
}
|
||||
impl SuperTrait for nofields {}
|
||||
impl SomeTrait for nofields {
|
||||
fn Method(&self, x: u32) -> u32 {
|
||||
self.Method(x);
|
||||
@ -186,59 +183,70 @@ enum SomeEnum<'a> {
|
||||
Ints(isize, isize),
|
||||
Floats(f64, f64),
|
||||
Strings(&'a str, &'a str, &'a str),
|
||||
MyTypes(MyType, MyType)
|
||||
MyTypes(MyType, MyType),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum SomeOtherEnum {
|
||||
SomeConst1,
|
||||
SomeConst2,
|
||||
SomeConst3
|
||||
SomeConst3,
|
||||
}
|
||||
|
||||
enum SomeStructEnum {
|
||||
EnumStruct{a:isize, b:isize},
|
||||
EnumStruct2{f1:MyType, f2:MyType},
|
||||
EnumStruct3{f1:MyType, f2:MyType, f3:SomeEnum<'static>}
|
||||
EnumStruct { a: isize, b: isize },
|
||||
EnumStruct2 { f1: MyType, f2: MyType },
|
||||
EnumStruct3 { f1: MyType, f2: MyType, f3: SomeEnum<'static> },
|
||||
}
|
||||
|
||||
fn matchSomeEnum(val: SomeEnum) {
|
||||
match val {
|
||||
SomeEnum::Ints(int1, int2) => { println(&(int1+int2).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()); }
|
||||
SomeEnum::Ints(int1, int2) => {
|
||||
println(&(int1 + int2).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) {
|
||||
match se {
|
||||
SomeStructEnum::EnumStruct{a:a, ..} => println(&a.to_string()),
|
||||
SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(&f_2.field1.to_string()),
|
||||
SomeStructEnum::EnumStruct3{f1, ..} => println(&f1.field1.to_string()),
|
||||
SomeStructEnum::EnumStruct { a: a, .. } => println(&a.to_string()),
|
||||
SomeStructEnum::EnumStruct2 { f1: f1, f2: f_2 } => println(&f_2.field1.to_string()),
|
||||
SomeStructEnum::EnumStruct3 { f1, .. } => println(&f1.field1.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn matchSomeStructEnum2(se: SomeStructEnum) {
|
||||
use SomeStructEnum::*;
|
||||
match se {
|
||||
EnumStruct{a: ref aaa, ..} => println(&aaa.to_string()),
|
||||
EnumStruct2{f1, f2: f2} => println(&f1.field1.to_string()),
|
||||
EnumStruct3{f1, f3: SomeEnum::Ints(..), f2} => println(&f1.field1.to_string()),
|
||||
_ => {},
|
||||
EnumStruct { a: ref aaa, .. } => println(&aaa.to_string()),
|
||||
EnumStruct2 { f1, f2: f2 } => println(&f1.field1.to_string()),
|
||||
EnumStruct3 { f1, f3: SomeEnum::Ints(..), f2 } => println(&f1.field1.to_string()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn matchSomeOtherEnum(val: SomeOtherEnum) {
|
||||
use SomeOtherEnum::{SomeConst2, SomeConst3};
|
||||
match val {
|
||||
SomeOtherEnum::SomeConst1 => { println("I'm const1."); }
|
||||
SomeConst2 | SomeConst3 => { println("I'm const2 or const3."); }
|
||||
SomeOtherEnum::SomeConst1 => {
|
||||
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);
|
||||
|
||||
println(&yy.to_string());
|
||||
@ -253,8 +261,8 @@ fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) {
|
||||
let x = 32.0f32;
|
||||
let _ = (x + ((x * x) + 1.0).sqrt()).ln();
|
||||
|
||||
let s: Box<SomeTrait> = box some_fields {field1: 43};
|
||||
let s2: Box<some_fields> = 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 s3 = box nofields;
|
||||
|
||||
s.Method(43);
|
||||
@ -307,8 +315,9 @@ mod macro_use_test {
|
||||
}
|
||||
}
|
||||
|
||||
fn main() { // foo
|
||||
let s = box some_fields {field1: 43};
|
||||
fn main() {
|
||||
// foo
|
||||
let s = box some_fields { field1: 43 };
|
||||
hello((43, "a".to_string()), *s);
|
||||
sub::sub2::hello();
|
||||
sub2::sub3::hello();
|
||||
@ -329,26 +338,24 @@ fn main() { // foo
|
||||
let vs = variable_str!(32);
|
||||
|
||||
let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
|
||||
let _ = blah {
|
||||
used_link_args: RefCell::new([]),
|
||||
};
|
||||
let _ = blah { used_link_args: RefCell::new([]) };
|
||||
let s1 = nofields;
|
||||
let s2 = SF { 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 = sub2::nested_struct{ field2: 55};
|
||||
let s2 = SF { 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 = sub2::nested_struct { field2: 55 };
|
||||
println(&s2.field1.to_string());
|
||||
let s5: MyType = box some_fields{ field1: 55};
|
||||
let s = SameDir::SameStruct{name: "Bob".to_string()};
|
||||
let s = SubDir::SubStruct{name:"Bob".to_string()};
|
||||
let s5: MyType = box some_fields { field1: 55 };
|
||||
let s = SameDir::SameStruct { name: "Bob".to_string() };
|
||||
let s = SubDir::SubStruct { name: "Bob".to_string() };
|
||||
let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5);
|
||||
let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
|
||||
matchSomeEnum(s6);
|
||||
matchSomeEnum(s7);
|
||||
let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
|
||||
matchSomeOtherEnum(s8);
|
||||
let s9: SomeStructEnum = SomeStructEnum::EnumStruct2{ f1: box some_fields{ field1:10 },
|
||||
f2: box s2 };
|
||||
let s9: SomeStructEnum =
|
||||
SomeStructEnum::EnumStruct2 { f1: box some_fields { field1: 10 }, f2: box s2 };
|
||||
matchSomeStructEnum(s9);
|
||||
|
||||
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);
|
||||
|
||||
pub trait Error {
|
||||
}
|
||||
pub trait Error {}
|
||||
|
||||
impl Error + 'static {
|
||||
pub fn is<T: Error + 'static>(&self) -> bool {
|
||||
@ -437,13 +443,13 @@ fn test_format_args() {
|
||||
print!("x is {}, y is {1}, name is {n}", x, y, n = name);
|
||||
}
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
static EXTERN_FOO: u8;
|
||||
fn extern_foo(a: u8, b: i32) -> String;
|
||||
}
|
||||
|
||||
struct Rls699 {
|
||||
f: u32,
|
||||
f: u32,
|
||||
}
|
||||
|
||||
fn new(f: u32) -> Rls699 {
|
||||
|
@ -2,7 +2,7 @@
|
||||
#![feature(static_nobundle)]
|
||||
|
||||
#[link(name = "aaa", kind = "static-nobundle")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn native_func();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![crate_type = "staticlib"]
|
||||
|
||||
#[link(name = "foo", kind = "static")]
|
||||
extern {}
|
||||
extern "C" {}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,19 +1,21 @@
|
||||
#![feature(lang_items, no_core, auto_traits)]
|
||||
#![no_core]
|
||||
|
||||
#[lang="copy"]
|
||||
trait Copy { }
|
||||
#[lang = "copy"]
|
||||
trait Copy {}
|
||||
|
||||
#[lang="sized"]
|
||||
trait Sized { }
|
||||
#[lang = "sized"]
|
||||
trait Sized {}
|
||||
|
||||
#[lang = "freeze"]
|
||||
auto trait Freeze {}
|
||||
|
||||
#[lang="start"]
|
||||
fn start(_main: *const u8, _argc: isize, _argv: *const *const u8) -> isize { 0 }
|
||||
#[lang = "start"]
|
||||
fn start(_main: *const u8, _argc: isize, _argv: *const *const u8) -> isize {
|
||||
0
|
||||
}
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
fn _foo() -> [u8; 16];
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,9 @@
|
||||
// For linking libstdc++ on MinGW
|
||||
#![cfg_attr(all(windows, target_env = "gnu"), feature(static_nobundle))]
|
||||
|
||||
extern { fn get() -> u32; }
|
||||
extern "C" {
|
||||
fn get() -> u32;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let i = unsafe { get() };
|
||||
|
@ -4,13 +4,13 @@
|
||||
extern crate foo;
|
||||
|
||||
#[link(wasm_import_module = "./me")]
|
||||
extern {
|
||||
extern "C" {
|
||||
#[link_name = "me_in_dep"]
|
||||
fn dep();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn foo() {
|
||||
pub extern "C" fn foo() {
|
||||
unsafe {
|
||||
foo::dep();
|
||||
dep();
|
||||
|
@ -2,6 +2,6 @@
|
||||
#![deny(warnings)]
|
||||
|
||||
#[link(wasm_import_module = "./dep")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn dep();
|
||||
}
|
||||
|
@ -6,13 +6,15 @@ extern crate libc;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[link(name = "CoreFoundation", kind = "framework")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn CFRunLoopGetTypeID() -> libc::c_ulong;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn main() {
|
||||
unsafe { CFRunLoopGetTypeID(); }
|
||||
unsafe {
|
||||
CFRunLoopGetTypeID();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
|
@ -5,7 +5,7 @@ pub trait Foo {
|
||||
}
|
||||
|
||||
#[doc(alias = "foo")] //~ ERROR
|
||||
extern {}
|
||||
extern "C" {}
|
||||
|
||||
#[doc(alias = "bar")] //~ ERROR
|
||||
impl Bar {
|
||||
@ -17,5 +17,7 @@ impl Bar {
|
||||
impl Foo for Bar {
|
||||
#[doc(alias = "assoc")] //~ ERROR
|
||||
type X = i32;
|
||||
fn foo() -> Self::X { 0 }
|
||||
fn foo() -> Self::X {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,6 @@ macro_rules! some_macro {
|
||||
() => {};
|
||||
}
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
pub type ExternType;
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn extern_c_fn();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![feature(extern_types)]
|
||||
|
||||
mod sub {
|
||||
extern {
|
||||
extern "C" {
|
||||
/// Another extern type.
|
||||
pub type C2;
|
||||
pub fn f2();
|
||||
@ -10,7 +10,7 @@ mod sub {
|
||||
}
|
||||
|
||||
pub mod sub2 {
|
||||
extern {
|
||||
extern "C" {
|
||||
// @has foreigntype_reexport/sub2/foreigntype.C.html
|
||||
pub type C;
|
||||
// @has foreigntype_reexport/sub2/fn.f.html
|
||||
@ -21,7 +21,7 @@ pub mod sub2 {
|
||||
}
|
||||
|
||||
mod sub3 {
|
||||
extern {
|
||||
extern "C" {
|
||||
pub type C4;
|
||||
pub fn f4();
|
||||
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="fn"]' 'f2'
|
||||
// @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="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::f as f3;'
|
||||
// @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/fn.f4.html
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![feature(extern_types)]
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
// @has foreigntype/foreigntype.ExtType.html
|
||||
pub type ExtType;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#![crate_name = "foo"]
|
||||
|
||||
mod mod1 {
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn public_fn();
|
||||
fn private_fn();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![crate_name = "foo"]
|
||||
|
||||
mod mod1 {
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn public_fn();
|
||||
fn private_fn();
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
extern {
|
||||
extern "C" {
|
||||
// @has issue_22038/fn.foo1.html \
|
||||
// '//*[@class="rust fn"]' 'pub unsafe extern "C" fn foo1()'
|
||||
pub fn foo1();
|
||||
@ -12,7 +12,7 @@ extern "system" {
|
||||
|
||||
// @has issue_22038/fn.bar.html \
|
||||
// '//*[@class="rust fn"]' 'pub extern "C" fn bar()'
|
||||
pub extern fn bar() {}
|
||||
pub extern "C" fn bar() {}
|
||||
|
||||
// @has issue_22038/fn.baz.html \
|
||||
// '//*[@class="rust fn"]' 'pub extern "system" fn baz()'
|
||||
|
@ -7,7 +7,7 @@
|
||||
// correctly, then linking will fail.
|
||||
|
||||
/// ```
|
||||
/// extern {
|
||||
/// extern "C" {
|
||||
/// fn __sanitizer_print_stack_trace();
|
||||
/// }
|
||||
///
|
||||
|
@ -7,7 +7,7 @@ pub mod foo_mod {
|
||||
pub struct __Thing {}
|
||||
}
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
// @matches 'foo/fn.foo_ffn.html' '//h1' 'Function foo::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'
|
||||
#[macro_export]
|
||||
macro_rules! foo_macro {
|
||||
() => ();
|
||||
() => {};
|
||||
}
|
||||
|
||||
// @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'
|
||||
pub static FOO_STATIC: FooStruct = FooStruct;
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
// @matches 'foo/static.FOO_FSTATIC.html' '//h1' 'Static foo::FOO_FSTATIC'
|
||||
pub static FOO_FSTATIC: FooStruct;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ use std::path::PathBuf;
|
||||
fn switch_stdout_to(file: File) {
|
||||
use std::os::unix::prelude::*;
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
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;
|
||||
|
||||
unsafe {
|
||||
let rc = SetStdHandle(STD_OUTPUT_HANDLE,
|
||||
file.into_raw_handle() as *mut _);
|
||||
let rc = SetStdHandle(STD_OUTPUT_HANDLE, file.into_raw_handle() as *mut _);
|
||||
assert!(rc != 0);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn rust_get_test_int() -> libc::intptr_t;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#![crate_name="anonexternmod"]
|
||||
#![crate_name = "anonexternmod"]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_get_test_int() -> libc::intptr_t;
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
#![crate_name="foreign_lib"]
|
||||
|
||||
#![crate_name = "foreign_lib"]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
pub mod rustrt {
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_get_test_int() -> libc::intptr_t;
|
||||
}
|
||||
}
|
||||
@ -14,7 +13,7 @@ pub mod rustrt {
|
||||
pub mod rustrt2 {
|
||||
extern crate libc;
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
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
|
||||
// importing the same symbol under different types.
|
||||
// See https://github.com/rust-lang/rust/issues/32740.
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_get_test_int() -> *const u8;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ mod rustrt {
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_get_test_int() -> libc::intptr_t;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
// ignore-wasm32-bare no libc to test ffi with
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn rust_int8_to_int32(_: i8) -> i32;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#![crate_name="anonexternmod"]
|
||||
#![crate_name = "anonexternmod"]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_get_test_int() -> libc::intptr_t;
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
#![crate_name="anonexternmod"]
|
||||
#![crate_name = "anonexternmod"]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_get_test_int() -> libc::intptr_t;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![crate_name="externcallback"]
|
||||
#![crate_name = "externcallback"]
|
||||
#![crate_type = "lib"]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
@ -8,10 +8,11 @@ pub mod rustrt {
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t)
|
||||
-> libc::uintptr_t;
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(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 {
|
||||
if data == 1 {
|
||||
data
|
||||
} else {
|
||||
fact(data - 1) * data
|
||||
}
|
||||
pub extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
if data == 1 { data } else { fact(data - 1) * data }
|
||||
}
|
||||
|
17
src/test/ui/abi/extern/extern-call-deep.rs
vendored
17
src/test/ui/abi/extern/extern-call-deep.rs
vendored
@ -10,19 +10,16 @@ mod rustrt {
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t)
|
||||
-> libc::uintptr_t;
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t,
|
||||
) -> libc::uintptr_t;
|
||||
}
|
||||
}
|
||||
|
||||
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
if data == 1 {
|
||||
data
|
||||
} else {
|
||||
count(data - 1) + 1
|
||||
}
|
||||
extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
if data == 1 { data } else { count(data - 1) + 1 }
|
||||
}
|
||||
|
||||
fn count(n: libc::uintptr_t) -> libc::uintptr_t {
|
||||
|
23
src/test/ui/abi/extern/extern-call-deep2.rs
vendored
23
src/test/ui/abi/extern/extern-call-deep2.rs
vendored
@ -1,7 +1,6 @@
|
||||
// run-pass
|
||||
#![allow(unused_must_use)]
|
||||
// ignore-emscripten no threads support
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
@ -11,19 +10,16 @@ mod rustrt {
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t)
|
||||
-> libc::uintptr_t;
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t,
|
||||
) -> libc::uintptr_t;
|
||||
}
|
||||
}
|
||||
|
||||
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
if data == 1 {
|
||||
data
|
||||
} else {
|
||||
count(data - 1) + 1
|
||||
}
|
||||
extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
if data == 1 { data } else { count(data - 1) + 1 }
|
||||
}
|
||||
|
||||
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() {
|
||||
// Make sure we're on a thread with small Rust stacks (main currently
|
||||
// has a large stack)
|
||||
thread::spawn(move|| {
|
||||
thread::spawn(move || {
|
||||
let result = count(1000);
|
||||
println!("result = {}", result);
|
||||
assert_eq!(result, 1000);
|
||||
}).join();
|
||||
})
|
||||
.join();
|
||||
}
|
||||
|
17
src/test/ui/abi/extern/extern-call-indirect.rs
vendored
17
src/test/ui/abi/extern/extern-call-indirect.rs
vendored
@ -9,19 +9,16 @@ mod rustrt {
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t)
|
||||
-> libc::uintptr_t;
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t,
|
||||
) -> libc::uintptr_t;
|
||||
}
|
||||
}
|
||||
|
||||
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
if data == 1 {
|
||||
data
|
||||
} else {
|
||||
fact(data - 1) * data
|
||||
}
|
||||
extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
if data == 1 { data } else { fact(data - 1) * data }
|
||||
}
|
||||
|
||||
fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
|
||||
|
23
src/test/ui/abi/extern/extern-call-scrub.rs
vendored
23
src/test/ui/abi/extern/extern-call-scrub.rs
vendored
@ -5,7 +5,6 @@
|
||||
// directions
|
||||
|
||||
// ignore-emscripten no threads support
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
@ -15,19 +14,16 @@ mod rustrt {
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t)
|
||||
-> libc::uintptr_t;
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t,
|
||||
) -> libc::uintptr_t;
|
||||
}
|
||||
}
|
||||
|
||||
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
if data == 1 {
|
||||
data
|
||||
} else {
|
||||
count(data - 1) + count(data - 1)
|
||||
}
|
||||
extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
if data == 1 { data } else { count(data - 1) + count(data - 1) }
|
||||
}
|
||||
|
||||
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() {
|
||||
// Make sure we're on a thread with small Rust stacks (main currently
|
||||
// has a large stack)
|
||||
thread::spawn(move|| {
|
||||
thread::spawn(move || {
|
||||
let result = count(12);
|
||||
println!("result = {}", result);
|
||||
assert_eq!(result, 2048);
|
||||
}).join();
|
||||
})
|
||||
.join();
|
||||
}
|
||||
|
@ -8,17 +8,18 @@
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub struct TwoU16s {
|
||||
one: u16, two: u16
|
||||
one: u16,
|
||||
two: u16,
|
||||
}
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_dbg_extern_identity_TwoU16s(v: TwoU16s) -> TwoU16s;
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
unsafe {
|
||||
let x = TwoU16s {one: 22, two: 23};
|
||||
let x = TwoU16s { one: 22, two: 23 };
|
||||
let y = rust_dbg_extern_identity_TwoU16s(x);
|
||||
assert_eq!(x, y);
|
||||
}
|
||||
|
@ -8,17 +8,18 @@
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub struct TwoU32s {
|
||||
one: u32, two: u32
|
||||
one: u32,
|
||||
two: u32,
|
||||
}
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_dbg_extern_identity_TwoU32s(v: TwoU32s) -> TwoU32s;
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
unsafe {
|
||||
let x = TwoU32s {one: 22, two: 23};
|
||||
let x = TwoU32s { one: 22, two: 23 };
|
||||
let y = rust_dbg_extern_identity_TwoU32s(x);
|
||||
assert_eq!(x, y);
|
||||
}
|
||||
|
@ -8,17 +8,18 @@
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub struct TwoU64s {
|
||||
one: u64, two: u64
|
||||
one: u64,
|
||||
two: u64,
|
||||
}
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_dbg_extern_identity_TwoU64s(v: TwoU64s) -> TwoU64s;
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
unsafe {
|
||||
let x = TwoU64s {one: 22, two: 23};
|
||||
let x = TwoU64s { one: 22, two: 23 };
|
||||
let y = rust_dbg_extern_identity_TwoU64s(x);
|
||||
assert_eq!(x, y);
|
||||
}
|
||||
|
7
src/test/ui/abi/extern/extern-pass-TwoU8s.rs
vendored
7
src/test/ui/abi/extern/extern-pass-TwoU8s.rs
vendored
@ -8,17 +8,18 @@
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub struct TwoU8s {
|
||||
one: u8, two: u8
|
||||
one: u8,
|
||||
two: u8,
|
||||
}
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_dbg_extern_identity_TwoU8s(v: TwoU8s) -> TwoU8s;
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
unsafe {
|
||||
let x = TwoU8s {one: 22, two: 23};
|
||||
let x = TwoU8s { one: 22, two: 23 };
|
||||
let y = rust_dbg_extern_identity_TwoU8s(x);
|
||||
assert_eq!(x, y);
|
||||
}
|
||||
|
3
src/test/ui/abi/extern/extern-pass-char.rs
vendored
3
src/test/ui/abi/extern/extern-pass-char.rs
vendored
@ -3,9 +3,8 @@
|
||||
|
||||
// Test a function that takes/returns a u8.
|
||||
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_dbg_extern_identity_u8(v: u8) -> u8;
|
||||
}
|
||||
|
||||
|
2
src/test/ui/abi/extern/extern-pass-double.rs
vendored
2
src/test/ui/abi/extern/extern-pass-double.rs
vendored
@ -2,7 +2,7 @@
|
||||
// ignore-wasm32-bare no libc for ffi testing
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_dbg_extern_identity_double(v: f64) -> f64;
|
||||
}
|
||||
|
||||
|
6
src/test/ui/abi/extern/extern-pass-empty.rs
vendored
6
src/test/ui/abi/extern/extern-pass-empty.rs
vendored
@ -27,7 +27,7 @@ struct ManyInts {
|
||||
struct Empty;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn rust_dbg_extern_empty_struct(v1: ManyInts, e: Empty, v2: ManyInts);
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ pub fn main() {
|
||||
arg3: 4,
|
||||
arg4: 5,
|
||||
arg5: 6,
|
||||
arg6: TwoU8s { one: 7, two: 8, }
|
||||
arg6: TwoU8s { one: 7, two: 8 },
|
||||
};
|
||||
let y = ManyInts {
|
||||
arg1: 1,
|
||||
@ -47,7 +47,7 @@ pub fn main() {
|
||||
arg3: 3,
|
||||
arg4: 4,
|
||||
arg5: 5,
|
||||
arg6: TwoU8s { one: 6, two: 7, }
|
||||
arg6: TwoU8s { one: 6, two: 7 },
|
||||
};
|
||||
let empty = Empty;
|
||||
rust_dbg_extern_empty_struct(x, empty, y);
|
||||
|
3
src/test/ui/abi/extern/extern-pass-u32.rs
vendored
3
src/test/ui/abi/extern/extern-pass-u32.rs
vendored
@ -3,9 +3,8 @@
|
||||
|
||||
// Test a function that takes/returns a u32.
|
||||
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_dbg_extern_identity_u32(v: u32) -> u32;
|
||||
}
|
||||
|
||||
|
3
src/test/ui/abi/extern/extern-pass-u64.rs
vendored
3
src/test/ui/abi/extern/extern-pass-u64.rs
vendored
@ -3,9 +3,8 @@
|
||||
|
||||
// Test a call to a function that takes/returns a u64.
|
||||
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_dbg_extern_identity_u64(v: u64) -> u64;
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,12 @@
|
||||
// ignore-wasm32-bare no libc to test ffi with
|
||||
|
||||
pub struct TwoU16s {
|
||||
one: u16, two: u16
|
||||
one: u16,
|
||||
two: u16,
|
||||
}
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_dbg_extern_return_TwoU16s() -> TwoU16s;
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,12 @@
|
||||
// ignore-wasm32-bare no libc to test ffi with
|
||||
|
||||
pub struct TwoU32s {
|
||||
one: u32, two: u32
|
||||
one: u32,
|
||||
two: u32,
|
||||
}
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub fn rust_dbg_extern_return_TwoU32s() -> TwoU32s;
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user