2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2014-10-12 22:00:45 -05:00
|
|
|
// Test method calls with self as an argument
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
static mut COUNT: usize = 1;
|
2014-10-12 22:00:45 -05:00
|
|
|
|
2015-03-30 08:38:27 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2014-10-12 22:00:45 -05: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-24 19:39:40 -05:00
|
|
|
Foo::qux(Box::new(self));
|
|
|
|
Foo::qux(Box::new(*x));
|
2014-10-12 22:00:45 -05: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-24 19:39:40 -05:00
|
|
|
Foo::qux(Box::new(x));
|
2014-10-12 22:00:45 -05:00
|
|
|
|
|
|
|
x.foo(&x);
|
|
|
|
|
2015-06-07 13:00:38 -05:00
|
|
|
unsafe { assert_eq!(COUNT, 2*3*3*3*5*5*5*7*7*7); }
|
2014-10-12 22:00:45 -05:00
|
|
|
}
|