summaryrefslogtreecommitdiffstats
path: root/src/test/ui/methods/method-self-arg.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/ui/methods/method-self-arg.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/ui/methods/method-self-arg.rs b/src/test/ui/methods/method-self-arg.rs
new file mode 100644
index 000000000..f738fa19c
--- /dev/null
+++ b/src/test/ui/methods/method-self-arg.rs
@@ -0,0 +1,46 @@
+// run-pass
+// Test method calls with self as an argument
+
+static mut COUNT: usize = 1;
+
+#[derive(Copy, Clone)]
+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));
+ }
+
+ 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));
+
+ x.foo(&x);
+
+ unsafe { assert_eq!(COUNT, 2*3*3*3*5*5*5*7*7*7); }
+}