about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorxizheyin <xizheyin@smail.nju.edu.cn>2025-08-14 12:19:02 +0800
committerxizheyin <xizheyin@smail.nju.edu.cn>2025-08-14 21:31:36 +0800
commitf5bc29568c39b6791f6d639d9a5ce065f7d4d889 (patch)
treea8a4b2f257aa76f3213fd12d267f534b8809964a /tests
parent8e7795415acaa9471b5eeb2301915d6996d289ec (diff)
downloadrust-f5bc29568c39b6791f6d639d9a5ce065f7d4d889.tar.gz
rust-f5bc29568c39b6791f6d639d9a5ce065f7d4d889.zip
Add test suggest-self-in-bare-function
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/parser/suggest-self-in-bare-function.rs25
-rw-r--r--tests/ui/parser/suggest-self-in-bare-function.stderr62
2 files changed, 87 insertions, 0 deletions
diff --git a/tests/ui/parser/suggest-self-in-bare-function.rs b/tests/ui/parser/suggest-self-in-bare-function.rs
new file mode 100644
index 00000000000..e7f2a12bcd0
--- /dev/null
+++ b/tests/ui/parser/suggest-self-in-bare-function.rs
@@ -0,0 +1,25 @@
+// We should not suggest `self` in bare functions.
+// And a note for RFC 1685 should not be shown.
+// See #144968
+
+//@ edition:2018
+
+fn is_even(value) -> bool { //~ ERROR expected one of `:`, `@`, or `|`, found `)`
+    value % 2 == 0
+}
+
+struct S;
+
+impl S {
+    fn is_even(value) -> bool { //~ ERROR expected one of `:`, `@`, or `|`, found `)`
+        value % 2 == 0
+    }
+}
+
+trait T {
+    fn is_even(value) -> bool { //~ ERROR expected one of `:`, `@`, or `|`, found `)`
+        value % 2 == 0
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/parser/suggest-self-in-bare-function.stderr b/tests/ui/parser/suggest-self-in-bare-function.stderr
new file mode 100644
index 00000000000..ff2bfc48eee
--- /dev/null
+++ b/tests/ui/parser/suggest-self-in-bare-function.stderr
@@ -0,0 +1,62 @@
+error: expected one of `:`, `@`, or `|`, found `)`
+  --> $DIR/suggest-self-in-bare-function.rs:7:17
+   |
+LL | fn is_even(value) -> bool {
+   |                 ^ expected one of `:`, `@`, or `|`
+   |
+   = note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
+help: if this is a `self` type, give it a parameter name
+   |
+LL | fn is_even(self: value) -> bool {
+   |            +++++
+help: if this is a parameter name, give it a type
+   |
+LL | fn is_even(value: TypeName) -> bool {
+   |                 ++++++++++
+help: if this is a type, explicitly ignore the parameter name
+   |
+LL | fn is_even(_: value) -> bool {
+   |            ++
+
+error: expected one of `:`, `@`, or `|`, found `)`
+  --> $DIR/suggest-self-in-bare-function.rs:14:21
+   |
+LL |     fn is_even(value) -> bool {
+   |                     ^ expected one of `:`, `@`, or `|`
+   |
+   = note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
+help: if this is a `self` type, give it a parameter name
+   |
+LL |     fn is_even(self: value) -> bool {
+   |                +++++
+help: if this is a parameter name, give it a type
+   |
+LL |     fn is_even(value: TypeName) -> bool {
+   |                     ++++++++++
+help: if this is a type, explicitly ignore the parameter name
+   |
+LL |     fn is_even(_: value) -> bool {
+   |                ++
+
+error: expected one of `:`, `@`, or `|`, found `)`
+  --> $DIR/suggest-self-in-bare-function.rs:20:21
+   |
+LL |     fn is_even(value) -> bool {
+   |                     ^ expected one of `:`, `@`, or `|`
+   |
+   = note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
+help: if this is a `self` type, give it a parameter name
+   |
+LL |     fn is_even(self: value) -> bool {
+   |                +++++
+help: if this is a parameter name, give it a type
+   |
+LL |     fn is_even(value: TypeName) -> bool {
+   |                     ++++++++++
+help: if this is a type, explicitly ignore the parameter name
+   |
+LL |     fn is_even(_: value) -> bool {
+   |                ++
+
+error: aborting due to 3 previous errors
+