Update tests for #[no_mangle] associated functions

This commit is contained in:
hyd-dev 2021-08-15 17:18:00 +08:00
parent 13fae3d074
commit 838ed1d754
No known key found for this signature in database
GPG Key ID: 74FA7FD5B8DA14B8
2 changed files with 16 additions and 2 deletions

View File

@ -3,11 +3,11 @@ fn exported_symbol() -> i32 {
123456
}
pub struct AssocFn;
struct AssocFn;
impl AssocFn {
#[no_mangle]
pub fn assoc_fn_as_exported_symbol() -> i32 {
fn assoc_fn_as_exported_symbol() -> i32 {
-123456
}
}

View File

@ -15,6 +15,16 @@ fn baz() -> i32 {
-3
}
struct AssocFn;
impl AssocFn {
#[no_mangle]
fn qux() -> i32 {
-4
}
}
fn main() {
// Repeat calls to make sure the `Instance` cache is not broken.
for _ in 0..3 {
@ -32,10 +42,12 @@ fn main() {
extern "Rust" {
fn bar() -> i32;
fn baz() -> i32;
fn qux() -> i32;
}
assert_eq!(unsafe { bar() }, -2);
assert_eq!(unsafe { baz() }, -3);
assert_eq!(unsafe { qux() }, -4);
#[allow(clashing_extern_declarations)]
{
@ -53,6 +65,7 @@ fn main() {
extern "C" {
fn bar() -> i32;
fn baz() -> i32;
fn qux() -> i32;
}
unsafe {
@ -61,6 +74,7 @@ fn main() {
};
assert_eq!(transmute(bar)(), -2);
assert_eq!(transmute(baz)(), -3);
assert_eq!(transmute(qux)(), -4);
}
}
}