Skip to content

Commit

Permalink
Update tests for #[no_mangle] associated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hyd-dev committed Aug 15, 2021
1 parent 13fae3d commit 838ed1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test-cargo-miri/exported-symbol-dep/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
14 changes: 14 additions & 0 deletions tests/run-pass/function_calls/exported_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)]
{
Expand All @@ -53,6 +65,7 @@ fn main() {
extern "C" {
fn bar() -> i32;
fn baz() -> i32;
fn qux() -> i32;
}

unsafe {
Expand All @@ -61,6 +74,7 @@ fn main() {
};
assert_eq!(transmute(bar)(), -2);
assert_eq!(transmute(baz)(), -3);
assert_eq!(transmute(qux)(), -4);
}
}
}
Expand Down

0 comments on commit 838ed1d

Please sign in to comment.