summaryrefslogtreecommitdiffstats
path: root/tests/ui/expr/malformed_closure
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /tests/ui/expr/malformed_closure
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/expr/malformed_closure')
-rw-r--r--tests/ui/expr/malformed_closure/block_instead_of_closure_in_arg.rs10
-rw-r--r--tests/ui/expr/malformed_closure/block_instead_of_closure_in_arg.stderr27
-rw-r--r--tests/ui/expr/malformed_closure/missing_block_in_fn_call.fixed10
-rw-r--r--tests/ui/expr/malformed_closure/missing_block_in_fn_call.rs10
-rw-r--r--tests/ui/expr/malformed_closure/missing_block_in_fn_call.stderr38
-rw-r--r--tests/ui/expr/malformed_closure/missing_block_in_let_binding.rs6
-rw-r--r--tests/ui/expr/malformed_closure/missing_block_in_let_binding.stderr16
-rw-r--r--tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.fixed9
-rw-r--r--tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.rs9
-rw-r--r--tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.stderr36
-rw-r--r--tests/ui/expr/malformed_closure/ruby_style_closure_successful_parse.rs7
-rw-r--r--tests/ui/expr/malformed_closure/ruby_style_closure_successful_parse.stderr25
12 files changed, 203 insertions, 0 deletions
diff --git a/tests/ui/expr/malformed_closure/block_instead_of_closure_in_arg.rs b/tests/ui/expr/malformed_closure/block_instead_of_closure_in_arg.rs
new file mode 100644
index 000000000..5e64fd5d2
--- /dev/null
+++ b/tests/ui/expr/malformed_closure/block_instead_of_closure_in_arg.rs
@@ -0,0 +1,10 @@
+fn main() {
+ let number = 2;
+ Some(true).filter({ //~ ERROR expected a `FnOnce(&bool)` closure, found `bool`
+ if number % 2 == 0 {
+ number == 0
+ } else {
+ number != 0
+ }
+ });
+}
diff --git a/tests/ui/expr/malformed_closure/block_instead_of_closure_in_arg.stderr b/tests/ui/expr/malformed_closure/block_instead_of_closure_in_arg.stderr
new file mode 100644
index 000000000..f70b32117
--- /dev/null
+++ b/tests/ui/expr/malformed_closure/block_instead_of_closure_in_arg.stderr
@@ -0,0 +1,27 @@
+error[E0277]: expected a `FnOnce(&bool)` closure, found `bool`
+ --> $DIR/block_instead_of_closure_in_arg.rs:3:23
+ |
+LL | Some(true).filter({
+ | _________________------_^
+ | | |
+ | | required by a bound introduced by this call
+LL | |/ if number % 2 == 0 {
+LL | || number == 0
+LL | || } else {
+LL | || number != 0
+LL | || }
+ | ||_________- this tail expression is of type `bool`
+LL | | });
+ | |______^ expected an `FnOnce(&bool)` closure, found `bool`
+ |
+ = help: the trait `for<'a> FnOnce<(&'a bool,)>` is not implemented for `bool`
+note: required by a bound in `Option::<T>::filter`
+ --> $SRC_DIR/core/src/option.rs:LL:COL
+help: you might have meant to create the closure instead of a block
+ |
+LL | Some(true).filter(|_| {
+ | +++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/expr/malformed_closure/missing_block_in_fn_call.fixed b/tests/ui/expr/malformed_closure/missing_block_in_fn_call.fixed
new file mode 100644
index 000000000..b81515cda
--- /dev/null
+++ b/tests/ui/expr/malformed_closure/missing_block_in_fn_call.fixed
@@ -0,0 +1,10 @@
+// run-rustfix
+fn main() {
+ let _ = vec![1, 2, 3].into_iter().map(|x| {
+ let y = x; //~ ERROR expected expression, found `let` statement
+ y
+ });
+ let _: () = foo(); //~ ERROR mismatched types
+}
+
+fn foo() {}
diff --git a/tests/ui/expr/malformed_closure/missing_block_in_fn_call.rs b/tests/ui/expr/malformed_closure/missing_block_in_fn_call.rs
new file mode 100644
index 000000000..e47ad562f
--- /dev/null
+++ b/tests/ui/expr/malformed_closure/missing_block_in_fn_call.rs
@@ -0,0 +1,10 @@
+// run-rustfix
+fn main() {
+ let _ = vec![1, 2, 3].into_iter().map(|x|
+ let y = x; //~ ERROR expected expression, found `let` statement
+ y
+ );
+ let _: () = foo; //~ ERROR mismatched types
+}
+
+fn foo() {}
diff --git a/tests/ui/expr/malformed_closure/missing_block_in_fn_call.stderr b/tests/ui/expr/malformed_closure/missing_block_in_fn_call.stderr
new file mode 100644
index 000000000..fbb7e0e4d
--- /dev/null
+++ b/tests/ui/expr/malformed_closure/missing_block_in_fn_call.stderr
@@ -0,0 +1,38 @@
+error: expected expression, found `let` statement
+ --> $DIR/missing_block_in_fn_call.rs:4:9
+ |
+LL | let _ = vec![1, 2, 3].into_iter().map(|x|
+ | --- while parsing the body of this closure
+LL | let y = x;
+ | ^^^
+ |
+ = note: only supported directly in conditions of `if` and `while` expressions
+help: you might have meant to open the body of the closure
+ |
+LL ~ let _ = vec![1, 2, 3].into_iter().map(|x| {
+LL | let y = x;
+LL | y
+LL ~ });
+ |
+
+error[E0308]: mismatched types
+ --> $DIR/missing_block_in_fn_call.rs:7:17
+ |
+LL | let _: () = foo;
+ | -- ^^^ expected `()`, found fn item
+ | |
+ | expected due to this
+...
+LL | fn foo() {}
+ | -------- function `foo` defined here
+ |
+ = note: expected unit type `()`
+ found fn item `fn() {foo}`
+help: use parentheses to call this function
+ |
+LL | let _: () = foo();
+ | ++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/expr/malformed_closure/missing_block_in_let_binding.rs b/tests/ui/expr/malformed_closure/missing_block_in_let_binding.rs
new file mode 100644
index 000000000..1ee215d15
--- /dev/null
+++ b/tests/ui/expr/malformed_closure/missing_block_in_let_binding.rs
@@ -0,0 +1,6 @@
+fn main() {
+ let x = |x|
+ let y = x; //~ ERROR expected expression, found `let` statement
+ let _ = () + ();
+ y
+}
diff --git a/tests/ui/expr/malformed_closure/missing_block_in_let_binding.stderr b/tests/ui/expr/malformed_closure/missing_block_in_let_binding.stderr
new file mode 100644
index 000000000..d4640fba9
--- /dev/null
+++ b/tests/ui/expr/malformed_closure/missing_block_in_let_binding.stderr
@@ -0,0 +1,16 @@
+error: expected expression, found `let` statement
+ --> $DIR/missing_block_in_let_binding.rs:3:9
+ |
+LL | let x = |x|
+ | --- while parsing the body of this closure
+LL | let y = x;
+ | ^^^
+ |
+ = note: only supported directly in conditions of `if` and `while` expressions
+help: you might have meant to open the body of the closure
+ |
+LL | let x = |x| {
+ | +
+
+error: aborting due to previous error
+
diff --git a/tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.fixed b/tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.fixed
new file mode 100644
index 000000000..8014dc87c
--- /dev/null
+++ b/tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.fixed
@@ -0,0 +1,9 @@
+// run-rustfix
+fn main() {
+ let _ = vec![1, 2, 3].into_iter().map(|x| {
+ let y = x; //~ ERROR expected expression, found `let` statement
+ y
+ });
+ let _: () = foo(); //~ ERROR mismatched types
+}
+fn foo() {}
diff --git a/tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.rs b/tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.rs
new file mode 100644
index 000000000..9e4aca888
--- /dev/null
+++ b/tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.rs
@@ -0,0 +1,9 @@
+// run-rustfix
+fn main() {
+ let _ = vec![1, 2, 3].into_iter().map({|x|
+ let y = x; //~ ERROR expected expression, found `let` statement
+ y
+ });
+ let _: () = foo; //~ ERROR mismatched types
+}
+fn foo() {}
diff --git a/tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.stderr b/tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.stderr
new file mode 100644
index 000000000..5fc48d73b
--- /dev/null
+++ b/tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.stderr
@@ -0,0 +1,36 @@
+error: expected expression, found `let` statement
+ --> $DIR/ruby_style_closure_parse_error.rs:4:9
+ |
+LL | let _ = vec![1, 2, 3].into_iter().map({|x|
+ | --- while parsing the body of this closure
+LL | let y = x;
+ | ^^^
+ |
+ = note: only supported directly in conditions of `if` and `while` expressions
+help: you might have meant to open the body of the closure, instead of enclosing the closure in a block
+ |
+LL - let _ = vec![1, 2, 3].into_iter().map({|x|
+LL + let _ = vec![1, 2, 3].into_iter().map(|x| {
+ |
+
+error[E0308]: mismatched types
+ --> $DIR/ruby_style_closure_parse_error.rs:7:17
+ |
+LL | let _: () = foo;
+ | -- ^^^ expected `()`, found fn item
+ | |
+ | expected due to this
+LL | }
+LL | fn foo() {}
+ | -------- function `foo` defined here
+ |
+ = note: expected unit type `()`
+ found fn item `fn() {foo}`
+help: use parentheses to call this function
+ |
+LL | let _: () = foo();
+ | ++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/expr/malformed_closure/ruby_style_closure_successful_parse.rs b/tests/ui/expr/malformed_closure/ruby_style_closure_successful_parse.rs
new file mode 100644
index 000000000..bb2e9c0a6
--- /dev/null
+++ b/tests/ui/expr/malformed_closure/ruby_style_closure_successful_parse.rs
@@ -0,0 +1,7 @@
+const x: usize =42;
+fn main() {
+ let p = Some(45).and_then({|x| //~ ERROR expected a `FnOnce({integer})` closure, found `Option<usize>`
+ 1 + 1;
+ Some(x * 2)
+ });
+}
diff --git a/tests/ui/expr/malformed_closure/ruby_style_closure_successful_parse.stderr b/tests/ui/expr/malformed_closure/ruby_style_closure_successful_parse.stderr
new file mode 100644
index 000000000..e44ec5ca9
--- /dev/null
+++ b/tests/ui/expr/malformed_closure/ruby_style_closure_successful_parse.stderr
@@ -0,0 +1,25 @@
+error[E0277]: expected a `FnOnce({integer})` closure, found `Option<usize>`
+ --> $DIR/ruby_style_closure_successful_parse.rs:3:31
+ |
+LL | let p = Some(45).and_then({|x|
+ | ______________________--------_^
+ | | |
+ | | required by a bound introduced by this call
+LL | | 1 + 1;
+LL | | Some(x * 2)
+ | | ----------- this tail expression is of type `Option<usize>`
+LL | | });
+ | |_____^ expected an `FnOnce({integer})` closure, found `Option<usize>`
+ |
+ = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<usize>`
+note: required by a bound in `Option::<T>::and_then`
+ --> $SRC_DIR/core/src/option.rs:LL:COL
+help: you might have meant to open the closure body instead of placing a closure within a block
+ |
+LL - let p = Some(45).and_then({|x|
+LL + let p = Some(45).and_then(|x| {
+ |
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.