2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2014-10-13 03:00:45 +00:00
|
|
|
// Test method calls with self as an argument
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
static mut COUNT: usize = 1;
|
2014-10-13 03:00:45 +00:00
|
|
|
|
2015-03-30 13:38:27 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2014-10-13 03:00:45 +00:00
|
|
|
struct Foo;
|
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
fn foo(self, x: &Foo) {
|
|
|
|
unsafe { COUNT *= 2; }
|
|
|
|
// Test internal call.
|
|
|
|
Foo::bar(&self);
|
|
|
|
Foo::bar(x);
|
|
|
|
|
|
|
|
Foo::baz(self);
|
|
|
|
Foo::baz(*x);
|
|
|
|
|
2021-08-25 00:39:40 +00:00
|
|
|
Foo::qux(Box::new(self));
|
|
|
|
Foo::qux(Box::new(*x));
|
2014-10-13 03:00:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn bar(&self) {
|
|
|
|
unsafe { COUNT *= 3; }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn baz(self) {
|
|
|
|
unsafe { COUNT *= 5; }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn qux(self: Box<Foo>) {
|
|
|
|
unsafe { COUNT *= 7; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x = Foo;
|
|
|
|
// Test external call.
|
|
|
|
Foo::bar(&x);
|
|
|
|
Foo::baz(x);
|
2021-08-25 00:39:40 +00:00
|
|
|
Foo::qux(Box::new(x));
|
2014-10-13 03:00:45 +00:00
|
|
|
|
|
|
|
x.foo(&x);
|
|
|
|
|
2015-06-07 18:00:38 +00:00
|
|
|
unsafe { assert_eq!(COUNT, 2*3*3*3*5*5*5*7*7*7); }
|
2014-10-13 03:00:45 +00:00
|
|
|
}
|