about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authormibac138 <5672750+mibac138@users.noreply.github.com>2020-10-14 22:27:48 +0200
committermibac138 <5672750+mibac138@users.noreply.github.com>2020-12-01 12:12:48 +0100
commit5404deeb64f4449079f5165ace6bfa1e52ca4b33 (patch)
treeb4a0cee6781d257ae05ebaf6d8a6cdffc1104946 /src/test/ui
parentc4926d01ada661d4fbffb0e5b1708ae5463d47b3 (diff)
downloadrust-5404deeb64f4449079f5165ace6bfa1e52ca4b33.tar.gz
rust-5404deeb64f4449079f5165ace6bfa1e52ca4b33.zip
Gracefully handle mistyping -> as => in function return type
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/fn/fn-fat-arrow-return.fixed18
-rw-r--r--src/test/ui/fn/fn-fat-arrow-return.rs18
-rw-r--r--src/test/ui/fn/fn-fat-arrow-return.stderr8
-rw-r--r--src/test/ui/fn/fn-fat-arrow-return2.rs10
-rw-r--r--src/test/ui/fn/fn-fat-arrow-return2.stderr14
5 files changed, 68 insertions, 0 deletions
diff --git a/src/test/ui/fn/fn-fat-arrow-return.fixed b/src/test/ui/fn/fn-fat-arrow-return.fixed
new file mode 100644
index 00000000000..0acca85aa67
--- /dev/null
+++ b/src/test/ui/fn/fn-fat-arrow-return.fixed
@@ -0,0 +1,18 @@
+// run-rustfix
+#![allow(unused)]
+fn a() -> usize { 0 }
+//~^ ERROR return types are denoted using `->`
+
+fn bar(_: u32) {}
+
+fn baz() -> *const dyn Fn(u32) { unimplemented!() }
+
+fn foo() {
+    match () {
+        _ if baz() == &bar as &dyn Fn(u32) => (),
+        () => (),
+    }
+}
+
+fn main() {
+}
diff --git a/src/test/ui/fn/fn-fat-arrow-return.rs b/src/test/ui/fn/fn-fat-arrow-return.rs
new file mode 100644
index 00000000000..4bdcd70d7fc
--- /dev/null
+++ b/src/test/ui/fn/fn-fat-arrow-return.rs
@@ -0,0 +1,18 @@
+// run-rustfix
+#![allow(unused)]
+fn a() => usize { 0 }
+//~^ ERROR return types are denoted using `->`
+
+fn bar(_: u32) {}
+
+fn baz() -> *const dyn Fn(u32) { unimplemented!() }
+
+fn foo() {
+    match () {
+        _ if baz() == &bar as &dyn Fn(u32) => (),
+        () => (),
+    }
+}
+
+fn main() {
+}
diff --git a/src/test/ui/fn/fn-fat-arrow-return.stderr b/src/test/ui/fn/fn-fat-arrow-return.stderr
new file mode 100644
index 00000000000..1fcdb18a514
--- /dev/null
+++ b/src/test/ui/fn/fn-fat-arrow-return.stderr
@@ -0,0 +1,8 @@
+error: return types are denoted using `->`
+  --> $DIR/fn-fat-arrow-return.rs:3:8
+   |
+LL | fn a() => usize { 0 }
+   |        ^^ help: use `->` instead
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/fn/fn-fat-arrow-return2.rs b/src/test/ui/fn/fn-fat-arrow-return2.rs
new file mode 100644
index 00000000000..316fa2cbf02
--- /dev/null
+++ b/src/test/ui/fn/fn-fat-arrow-return2.rs
@@ -0,0 +1,10 @@
+fn a() => impl Fn() => bool {
+    //~^ ERROR return types are denoted using `->`
+    //~| ERROR expected `;` or `{`, found `=>`
+    unimplemented!()
+}
+
+fn main() {
+    let foo = |a: bool| => bool { a };
+    dbg!(foo(false));
+}
diff --git a/src/test/ui/fn/fn-fat-arrow-return2.stderr b/src/test/ui/fn/fn-fat-arrow-return2.stderr
new file mode 100644
index 00000000000..a6f9fe3b573
--- /dev/null
+++ b/src/test/ui/fn/fn-fat-arrow-return2.stderr
@@ -0,0 +1,14 @@
+error: return types are denoted using `->`
+  --> $DIR/fn-fat-arrow-return2.rs:1:8
+   |
+LL | fn a() => impl Fn() => bool {
+   |        ^^ help: use `->` instead
+
+error: expected `;` or `{`, found `=>`
+  --> $DIR/fn-fat-arrow-return2.rs:1:21
+   |
+LL | fn a() => impl Fn() => bool {
+   |                     ^^ expected `;` or `{`
+
+error: aborting due to 2 previous errors
+