rust/tests/ui/methods/method-self-arg.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
769 B
Rust
Raw Normal View History

// run-pass
2014-10-13 03:00:45 +00:00
// Test method calls with self as an argument
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);
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);
Foo::qux(Box::new(x));
2014-10-13 03:00:45 +00:00
x.foo(&x);
unsafe { assert_eq!(COUNT, 2*3*3*3*5*5*5*7*7*7); }
2014-10-13 03:00:45 +00:00
}