<feed xmlns='http://www.w3.org/2005/Atom'>
<title>rust/tests/ui/expr, branch 1.76.0</title>
<subtitle>https://github.com/rust-lang/rust
</subtitle>
<id>http://git.dreamy.place/mirrors/rust/atom?h=1.76.0</id>
<link rel='self' href='http://git.dreamy.place/mirrors/rust/atom?h=1.76.0'/>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/'/>
<updated>2023-11-28T18:07:52+00:00</updated>
<entry>
<title>Suggest `let` or `==` on typo'd let-chain</title>
<updated>2023-11-28T18:07:52+00:00</updated>
<author>
<name>Esteban Küber</name>
<email>esteban@kuber.com.ar</email>
</author>
<published>2023-11-22T23:27:15+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=55e4e3e3932ef41353efd888ff96dfc96ec61bd3'/>
<id>urn:sha1:55e4e3e3932ef41353efd888ff96dfc96ec61bd3</id>
<content type='text'>
When encountering a bare assignment in a let-chain, suggest turning the
assignment into a `let` expression or an equality check.

```
error: expected expression, found `let` statement
  --&gt; $DIR/bad-if-let-suggestion.rs:5:8
   |
LL |     if let x = 1 &amp;&amp; i = 2 {}
   |        ^^^^^^^^^
   |
   = note: only supported directly in conditions of `if` and `while` expressions
help: you might have meant to continue the let-chain
   |
LL |     if let x = 1 &amp;&amp; let i = 2 {}
   |                     +++
help: you might have meant to compare for equality
   |
LL |     if let x = 1 &amp;&amp; i == 2 {}
   |                        +
```
</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>Address review comments</title>
<updated>2023-09-13T15:00:31+00:00</updated>
<author>
<name>Matthew Jasper</name>
<email>mjjasper1@gmail.com</email>
</author>
<published>2023-09-13T15:00:31+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=e324a59eb6ba1a7883bf23ff42d425ca96960f2a'/>
<id>urn:sha1:e324a59eb6ba1a7883bf23ff42d425ca96960f2a</id>
<content type='text'>
- Add doc comment to new type
- Restore "only supported directly in conditions of `if` and `while` expressions" note
- Rename variant with clearer name
</content>
</entry>
<entry>
<title>Reduce double errors for invalid let expressions</title>
<updated>2023-09-11T16:17:06+00:00</updated>
<author>
<name>Matthew Jasper</name>
<email>mjjasper1@gmail.com</email>
</author>
<published>2023-09-11T16:16:59+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=b011a0a13b4354080b3add0bb3f4445ddb8fd13b'/>
<id>urn:sha1:b011a0a13b4354080b3add0bb3f4445ddb8fd13b</id>
<content type='text'>
Previously some invalid let expressions would result in both a feature
error and a parsing error. Avoid this and ensure that we only emit the
parsing error when this happens.
</content>
</entry>
<entry>
<title>Move let expression checking to parsing</title>
<updated>2023-09-11T15:51:18+00:00</updated>
<author>
<name>Matthew Jasper</name>
<email>mjjasper1@gmail.com</email>
</author>
<published>2023-09-08T10:14:36+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=333388fd3c9fa03362a3c2a2675ab521c4ddb1ff'/>
<id>urn:sha1:333388fd3c9fa03362a3c2a2675ab521c4ddb1ff</id>
<content type='text'>
There was an incomplete version of the check in parsing and a second
version in AST validation. This meant that some, but not all, invalid
uses were allowed inside macros/disabled cfgs. It also means that later
passes have a hard time knowing when the let expression is in a valid
location, sometimes causing ICEs.

- Add a field to ExprKind::Let in AST/HIR to mark whether it's in a
  valid location.
- Suppress later errors and MIR construction for invalid let
  expressions.
</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>
