<feed xmlns='http://www.w3.org/2005/Atom'>
<title>rust/tests/ui/expr/malformed_closure, branch try-perf</title>
<subtitle>https://github.com/rust-lang/rust
</subtitle>
<id>http://git.dreamy.place/mirrors/rust/atom?h=try-perf</id>
<link rel='self' href='http://git.dreamy.place/mirrors/rust/atom?h=try-perf'/>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/'/>
<updated>2024-05-29T22:26:54+00:00</updated>
<entry>
<title>Use parenthetical notation for `Fn` traits</title>
<updated>2024-05-29T22:26:54+00:00</updated>
<author>
<name>Esteban Küber</name>
<email>esteban@kuber.com.ar</email>
</author>
<published>2024-05-29T21:42:40+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=e6bd6c2044352d842afb827f1fe0fd6f43c38413'/>
<id>urn:sha1:e6bd6c2044352d842afb827f1fe0fd6f43c38413</id>
<content type='text'>
Always use the `Fn(T) -&gt; R` format when printing closure traits instead of `Fn&lt;(T,), Output = R&gt;`.

Fix #67100:

```
error[E0277]: expected a `Fn()` closure, found `F`
 --&gt; file.rs:6:13
  |
6 |     call_fn(f)
  |     ------- ^ expected an `Fn()` closure, found `F`
  |     |
  |     required by a bound introduced by this call
  |
  = note: wrap the `F` in a closure with no arguments: `|| { /* code */ }`
note: required by a bound in `call_fn`
 --&gt; file.rs:1:15
  |
1 | fn call_fn&lt;F: Fn() -&gt; ()&gt;(f: &amp;F) {
  |               ^^^^^^^^^^ required by this bound in `call_fn`
help: consider further restricting this bound
  |
5 | fn call_any&lt;F: std::any::Any + Fn()&gt;(f: &amp;F) {
  |                              ++++++
```
</content>
</entry>
<entry>
<title>[AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives</title>
<updated>2024-02-16T20:02:50+00:00</updated>
<author>
<name>许杰友 Jieyou Xu (Joe)</name>
<email>jieyouxu@outlook.com</email>
</author>
<published>2024-02-16T20:02:50+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=ec2cc761bc7067712ecc7734502f703fe3b024c8'/>
<id>urn:sha1:ec2cc761bc7067712ecc7734502f703fe3b024c8</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Show number in error message even for one error</title>
<updated>2023-11-24T18:15:52+00:00</updated>
<author>
<name>Nilstrieb</name>
<email>48135649+Nilstrieb@users.noreply.github.com</email>
</author>
<published>2023-11-21T15:44:16+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=41e8d152dc5abb5a706999ada8b059d3420af8f3'/>
<id>urn:sha1:41e8d152dc5abb5a706999ada8b059d3420af8f3</id>
<content type='text'>
Co-authored-by: Adrian &lt;adrian.iosdev@gmail.com&gt;
</content>
</entry>
<entry>
<title>Pretty print Fn traits in rustc_on_unimplemented</title>
<updated>2023-11-02T20:57:05+00:00</updated>
<author>
<name>Michael Goulet</name>
<email>michael@errs.io</email>
</author>
<published>2023-10-05T01:50:00+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=c83f642f12d50dbd998f5064630985306d3021d9'/>
<id>urn:sha1:c83f642f12d50dbd998f5064630985306d3021d9</id>
<content type='text'>
</content>
</entry>
<entry>
<title>When expecting closure argument but finding block provide suggestion</title>
<updated>2023-10-23T20:41:15+00:00</updated>
<author>
<name>Esteban Küber</name>
<email>esteban@kuber.com.ar</email>
</author>
<published>2023-10-23T20:41:15+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=c1bfd46c7b2b5ec21275fdab2fa931c54f9b1f9c'/>
<id>urn:sha1:c1bfd46c7b2b5ec21275fdab2fa931c54f9b1f9c</id>
<content type='text'>
Detect if there is a potential typo where the `{` meant to open the
closure body was written before the body.

```
error[E0277]: expected a `FnOnce&lt;({integer},)&gt;` closure, found `Option&lt;usize&gt;`
  --&gt; $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&lt;usize&gt;`
LL | |     });
   | |_____^ expected an `FnOnce&lt;({integer},)&gt;` closure, found `Option&lt;usize&gt;`
   |
   = help: the trait `FnOnce&lt;({integer},)&gt;` is not implemented for `Option&lt;usize&gt;`
note: required by a bound in `Option::&lt;T&gt;::and_then`
  --&gt; $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| {
   |
```

Detect the potential typo where the closure header is missing.

```
error[E0277]: expected a `FnOnce&lt;(&amp;bool,)&gt;` closure, found `bool`
  --&gt; $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&lt;(&amp;bool,)&gt;` closure, found `bool`
   |
   = help: the trait `for&lt;'a&gt; FnOnce&lt;(&amp;'a bool,)&gt;` is not implemented for `bool`
note: required by a bound in `Option::&lt;T&gt;::filter`
  --&gt; $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(|_| {
   |                       +++
```

Partially address #27300.
</content>
</entry>
<entry>
<title>Detect ruby-style closure in parser</title>
<updated>2023-10-12T21:50:18+00:00</updated>
<author>
<name>Esteban Küber</name>
<email>esteban@kuber.com.ar</email>
</author>
<published>2023-10-11T23:20:41+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=6b2c6c7fd3860cc9e6fde3077b889abbd6a30892'/>
<id>urn:sha1:6b2c6c7fd3860cc9e6fde3077b889abbd6a30892</id>
<content type='text'>
When parsing a closure without a body that is surrounded by a block,
suggest moving the opening brace after the closure head.

Fix #116608.
</content>
</entry>
<entry>
<title>parser: provide better errors on closures with braces missing</title>
<updated>2023-02-23T10:05:13+00:00</updated>
<author>
<name>Yutaro Ohno</name>
<email>yutaro.ono.418@gmail.com</email>
</author>
<published>2023-02-23T07:42:52+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=0e42298674757bbb3563e0deda477044cce8271d'/>
<id>urn:sha1:0e42298674757bbb3563e0deda477044cce8271d</id>
<content type='text'>
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 `)`
 --&gt; ./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
 --&gt; ./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 `}`
 --&gt; ./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
 --&gt; ./main.rs:2:25
  |
2 |     let _x = Box::new(|x|x+1;);
  |                         ^    ^
  |
note: statement found outside of a block
 --&gt; ./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
 --&gt; ./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
```
</content>
</entry>
<entry>
<title>Move /src/test to /tests</title>
<updated>2023-01-11T09:32:08+00:00</updated>
<author>
<name>Albert Larsan</name>
<email>74931857+albertlarsan68@users.noreply.github.com</email>
</author>
<published>2023-01-05T08:13:28+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=cf2dff2b1e3fa55fa5415d524200070d0d7aacfe'/>
<id>urn:sha1:cf2dff2b1e3fa55fa5415d524200070d0d7aacfe</id>
<content type='text'>
</content>
</entry>
</feed>
