summaryrefslogtreecommitdiffstats
path: root/tests/ui/invalid-self-argument
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/invalid-self-argument')
-rw-r--r--tests/ui/invalid-self-argument/bare-fn-start.rs6
-rw-r--r--tests/ui/invalid-self-argument/bare-fn-start.stderr10
-rw-r--r--tests/ui/invalid-self-argument/bare-fn.rs5
-rw-r--r--tests/ui/invalid-self-argument/bare-fn.stderr8
-rw-r--r--tests/ui/invalid-self-argument/trait-fn.rs11
-rw-r--r--tests/ui/invalid-self-argument/trait-fn.stderr8
6 files changed, 48 insertions, 0 deletions
diff --git a/tests/ui/invalid-self-argument/bare-fn-start.rs b/tests/ui/invalid-self-argument/bare-fn-start.rs
new file mode 100644
index 000000000..7c580bc5a
--- /dev/null
+++ b/tests/ui/invalid-self-argument/bare-fn-start.rs
@@ -0,0 +1,6 @@
+fn a(&self) { }
+//~^ ERROR `self` parameter is only allowed in associated functions
+//~| NOTE not semantically valid as function parameter
+//~| NOTE associated functions are those in `impl` or `trait` definitions
+
+fn main() { }
diff --git a/tests/ui/invalid-self-argument/bare-fn-start.stderr b/tests/ui/invalid-self-argument/bare-fn-start.stderr
new file mode 100644
index 000000000..37753e61f
--- /dev/null
+++ b/tests/ui/invalid-self-argument/bare-fn-start.stderr
@@ -0,0 +1,10 @@
+error: `self` parameter is only allowed in associated functions
+ --> $DIR/bare-fn-start.rs:1:6
+ |
+LL | fn a(&self) { }
+ | ^^^^^ not semantically valid as function parameter
+ |
+ = note: associated functions are those in `impl` or `trait` definitions
+
+error: aborting due to previous error
+
diff --git a/tests/ui/invalid-self-argument/bare-fn.rs b/tests/ui/invalid-self-argument/bare-fn.rs
new file mode 100644
index 000000000..342bdc31a
--- /dev/null
+++ b/tests/ui/invalid-self-argument/bare-fn.rs
@@ -0,0 +1,5 @@
+fn b(foo: u32, &mut self) { }
+//~^ ERROR unexpected `self` parameter in function
+//~| NOTE must be the first parameter of an associated function
+
+fn main() { }
diff --git a/tests/ui/invalid-self-argument/bare-fn.stderr b/tests/ui/invalid-self-argument/bare-fn.stderr
new file mode 100644
index 000000000..ff2217b5e
--- /dev/null
+++ b/tests/ui/invalid-self-argument/bare-fn.stderr
@@ -0,0 +1,8 @@
+error: unexpected `self` parameter in function
+ --> $DIR/bare-fn.rs:1:16
+ |
+LL | fn b(foo: u32, &mut self) { }
+ | ^^^^^^^^^ must be the first parameter of an associated function
+
+error: aborting due to previous error
+
diff --git a/tests/ui/invalid-self-argument/trait-fn.rs b/tests/ui/invalid-self-argument/trait-fn.rs
new file mode 100644
index 000000000..5ccea5895
--- /dev/null
+++ b/tests/ui/invalid-self-argument/trait-fn.rs
@@ -0,0 +1,11 @@
+struct Foo {}
+
+impl Foo {
+ fn c(foo: u32, self) {}
+ //~^ ERROR unexpected `self` parameter in function
+ //~| NOTE must be the first parameter of an associated function
+
+ fn good(&mut self, foo: u32) {}
+}
+
+fn main() { }
diff --git a/tests/ui/invalid-self-argument/trait-fn.stderr b/tests/ui/invalid-self-argument/trait-fn.stderr
new file mode 100644
index 000000000..b9887af96
--- /dev/null
+++ b/tests/ui/invalid-self-argument/trait-fn.stderr
@@ -0,0 +1,8 @@
+error: unexpected `self` parameter in function
+ --> $DIR/trait-fn.rs:4:20
+ |
+LL | fn c(foo: u32, self) {}
+ | ^^^^ must be the first parameter of an associated function
+
+error: aborting due to previous error
+