2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2015-03-19 22:39:03 +00:00
|
|
|
//@ aux-build:trait_safety_lib.rs
|
2014-12-10 22:24:10 +00:00
|
|
|
|
|
|
|
// Simple smoke test that unsafe traits can be compiled across crates.
|
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2015-03-19 22:39:03 +00:00
|
|
|
extern crate trait_safety_lib as lib;
|
2014-12-10 22:24:10 +00:00
|
|
|
|
|
|
|
use lib::Foo;
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
struct Bar { x: isize }
|
2014-12-10 22:24:10 +00:00
|
|
|
unsafe impl Foo for Bar {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn foo(&self) -> isize { self.x }
|
2014-12-10 22:24:10 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn take_foo<F:Foo>(f: &F) -> isize { f.foo() }
|
2014-12-10 22:24:10 +00:00
|
|
|
|
|
|
|
fn main() {
|
2015-03-26 00:06:52 +00:00
|
|
|
let x: isize = 22;
|
2014-12-10 22:24:10 +00:00
|
|
|
assert_eq!(22, take_foo(&x));
|
|
|
|
|
|
|
|
let x: Bar = Bar { x: 23 };
|
|
|
|
assert_eq!(23, take_foo(&x));
|
|
|
|
}
|