-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #116645 - estebank:issue-116608, r=oli-obk
Detect ruby-style closure in parser When parsing a closure without a body that is surrounded by a block, suggest moving the opening brace after the closure head. Fix #116608.
- Loading branch information
Showing
13 changed files
with
232 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/ui/expr/malformed_closure/missing_block_in_fn_call.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
10 changes: 10 additions & 0 deletions
10
tests/ui/expr/malformed_closure/missing_block_in_fn_call.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
38 changes: 38 additions & 0 deletions
38
tests/ui/expr/malformed_closure/missing_block_in_fn_call.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
6 changes: 6 additions & 0 deletions
6
tests/ui/expr/malformed_closure/missing_block_in_let_binding.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fn main() { | ||
let x = |x| | ||
let y = x; //~ ERROR expected expression, found `let` statement | ||
let _ = () + (); | ||
y | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ui/expr/malformed_closure/missing_block_in_let_binding.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
9 changes: 9 additions & 0 deletions
9
tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
9 changes: 9 additions & 0 deletions
9
tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
36 changes: 36 additions & 0 deletions
36
tests/ui/expr/malformed_closure/ruby_style_closure_parse_error.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub fn test() { | ||
foo(|_|) //~ ERROR expected expression, found `)` | ||
//~^ ERROR cannot find function `foo` in this scope | ||
} | ||
|
||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters