rust/tests
Yutaro Ohno 0e42298674 parser: provide better errors on closures with braces missing
We currently provide wrong suggestions and unhelpful errors on closure
bodies with braces missing. For example, given the following code:

```
fn main() {
    let _x = Box::new(|x|x+1;);
}
```

the current output is like this:

```
error: expected expression, found `)`
 --> ./main.rs:2:30
  |
2 |     let _x = Box::new(|x|x+1;);
  |                              ^ expected expression

error: closure bodies that contain statements must be surrounded by braces
 --> ./main.rs:2:25
  |
2 |     let _x = Box::new(|x|x+1;);
  |                         ^
3 | }
  | ^
  |

...

help: try adding braces
  |
2 ~     let _x = Box::new(|x| {x+1;);
3 ~ }}

...

error: expected `;`, found `}`
 --> ./main.rs:2:32
  |
2 |     let _x = Box::new(|x|x+1;);
  |                                ^ help: add `;` here
3 | }
  | - unexpected token

error: aborting due to 3 previous errors
```

This commit allows outputting correct suggestions and errors. The above
code would output like this:

```
error: closure bodies that contain statements must be surrounded by braces
 --> ./main.rs:2:25
  |
2 |     let _x = Box::new(|x|x+1;);
  |                         ^    ^
  |
note: statement found outside of a block
 --> ./main.rs:2:29
  |
2 |     let _x = Box::new(|x|x+1;);
  |                          ---^ this `;` turns the preceding closure into a statement
  |                          |
  |                          this expression is a statement because of the trailing semicolon
note: the closure body may be incorrectly delimited
 --> ./main.rs:2:23
  |
2 |     let _x = Box::new(|x|x+1;);
  |                       ^^^^^^ - ...but likely you meant the closure to end here
  |                       |
  |                       this is the parsed closure...
help: try adding braces
  |
2 |     let _x = Box::new(|x| {x+1;});
  |                           +    +

error: aborting due to previous error
```
2023-02-23 19:05:13 +09:00
..
assembly Update the minimum external LLVM to 14 2023-02-10 16:06:25 -08:00
auxiliary
codegen Auto merge of #107921 - cjgillot:codegen-overflow-check, r=tmiasko 2023-02-19 18:17:26 +00:00
codegen-units
debuginfo
incremental
mir-opt Rollup merge of #108246 - saethlin:instcombine-redundant-casts, r=compiler-errors 2023-02-22 10:35:09 +01:00
pretty
run-make errors: fix translation's run-make test 2023-02-22 09:15:54 +00:00
run-make-fulldeps various: translation resources from cg backend 2023-02-22 09:15:54 +00:00
run-pass-valgrind
rustdoc rustdoc: update test case with intra-doc link pointing to method 2023-02-22 08:40:47 -07:00
rustdoc-gui Rollup merge of #107783 - notriddle:notriddle/item-table-ul, r=GuillaumeGomez 2023-02-19 13:03:41 +05:30
rustdoc-js
rustdoc-js-std rustdoc: hide reference methods in search index 2023-02-16 17:21:57 -07:00
rustdoc-json Add regression test for #107677 2023-02-18 18:28:17 +01:00
rustdoc-ui Rollup merge of #108285 - BoxyUwU:remove_pick_stable_before_unstable_flag, r=oli-obk 2023-02-21 14:20:00 +05:30
ui parser: provide better errors on closures with braces missing 2023-02-23 19:05:13 +09:00
ui-fulldeps various: translation resources from cg backend 2023-02-22 09:15:54 +00:00
COMPILER_TESTS.md