From ef24de24a82fe681581cc130f342363c47c0969a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 7 Jun 2024 07:48:48 +0200 Subject: Merging upstream version 1.75.0+dfsg1. Signed-off-by: Daniel Baumann --- .../block_instead_of_closure_in_arg.rs | 10 ++++++ .../block_instead_of_closure_in_arg.stderr | 27 +++++++++++++++ .../missing_block_in_fn_call.fixed | 10 ++++++ .../malformed_closure/missing_block_in_fn_call.rs | 10 ++++++ .../missing_block_in_fn_call.stderr | 38 ++++++++++++++++++++++ .../missing_block_in_let_binding.rs | 6 ++++ .../missing_block_in_let_binding.stderr | 16 +++++++++ .../ruby_style_closure_parse_error.fixed | 9 +++++ .../ruby_style_closure_parse_error.rs | 9 +++++ .../ruby_style_closure_parse_error.stderr | 36 ++++++++++++++++++++ .../ruby_style_closure_successful_parse.rs | 7 ++++ .../ruby_style_closure_successful_parse.stderr | 25 ++++++++++++++ 12 files changed, 203 insertions(+) create mode 100644 tests/ui/expr/malformed_closure/block_instead_of_closure_in_arg.rs create mode 100644 tests/ui/expr/malformed_closure/block_instead_of_closure_in_arg.stderr create mode 100644 tests/ui/expr/malformed_closure/missing_block_in_fn_call.fixed create mode 100644 tests/ui/expr/malformed_closure/missing_block_in_fn_call.rs create mode 100644 tests/ui/expr/malformed_closure/missing_block_in_fn_call.stderr create mode 100644 tests/ui/expr/malformed_closure/missing_block_in_let_binding.rs create mode 100644 tests/ui/expr/malformed_closure/missing_block_in_let_binding.stderr create mode 100644 tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.fixed create mode 100644 tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.rs create mode 100644 tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.stderr create mode 100644 tests/ui/expr/malformed_closure/ruby_style_closure_successful_parse.rs create mode 100644 tests/ui/expr/malformed_closure/ruby_style_closure_successful_parse.stderr (limited to 'tests/ui/expr/malformed_closure') 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::::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` + 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` + --> $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` +LL | | }); + | |_____^ expected an `FnOnce({integer})` closure, found `Option` + | + = help: the trait `FnOnce<({integer},)>` is not implemented for `Option` +note: required by a bound in `Option::::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`. -- cgit v1.2.3