about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/test/ui/type-alias-impl-trait/closures_in_branches.rs31
-rw-r--r--src/test/ui/type-alias-impl-trait/closures_in_branches.stderr11
2 files changed, 42 insertions, 0 deletions
diff --git a/src/test/ui/type-alias-impl-trait/closures_in_branches.rs b/src/test/ui/type-alias-impl-trait/closures_in_branches.rs
new file mode 100644
index 00000000000..a1a9401acc2
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/closures_in_branches.rs
@@ -0,0 +1,31 @@
+#![feature(type_alias_impl_trait)]
+
+type Foo = impl std::ops::FnOnce(String) -> usize;
+
+fn foo(b: bool) -> Foo {
+    if b {
+        |x| x.len()
+    } else {
+        panic!()
+    }
+}
+
+
+type Foo1 = impl std::ops::FnOnce(String) -> usize;
+fn foo1(b: bool) -> Foo1 {
+    |x| x.len()
+}
+
+fn bar(b: bool) -> impl std::ops::FnOnce(String) -> usize {
+    if b {
+        |x| x.len() //~ ERROR type annotations needed
+    } else {
+        panic!()
+    }
+}
+
+fn bar1(b: bool) -> impl std::ops::FnOnce(String) -> usize {
+    |x| x.len()
+}
+
+fn main() {}
diff --git a/src/test/ui/type-alias-impl-trait/closures_in_branches.stderr b/src/test/ui/type-alias-impl-trait/closures_in_branches.stderr
new file mode 100644
index 00000000000..cfa4a4b9d20
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/closures_in_branches.stderr
@@ -0,0 +1,11 @@
+error[E0282]: type annotations needed
+  --> $DIR/closures_in_branches.rs:21:10
+   |
+LL |         |x| x.len()
+   |          ^ consider giving this closure parameter a type
+   |
+   = note: type must be known at this point
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.