<feed xmlns='http://www.w3.org/2005/Atom'>
<title>rust/compiler/rustc_ast_pretty/src/pprust/state, branch 1.78.0</title>
<subtitle>https://github.com/rust-lang/rust
</subtitle>
<id>http://git.dreamy.place/mirrors/rust/atom?h=1.78.0</id>
<link rel='self' href='http://git.dreamy.place/mirrors/rust/atom?h=1.78.0'/>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/'/>
<updated>2024-02-29T16:18:40+00:00</updated>
<entry>
<title>AST: Refactor type alias where clauses</title>
<updated>2024-02-29T16:18:40+00:00</updated>
<author>
<name>León Orell Valerian Liehr</name>
<email>me@fmease.dev</email>
</author>
<published>2024-02-19T13:25:33+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=2b8060578a4a7dafc74f782850c86762ec05857a'/>
<id>urn:sha1:2b8060578a4a7dafc74f782850c86762ec05857a</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Add `ErrorGuaranteed` to `ast::ExprKind::Err`</title>
<updated>2024-02-25T21:24:31+00:00</updated>
<author>
<name>Lieselotte</name>
<email>52315535+she3py@users.noreply.github.com</email>
</author>
<published>2024-02-25T21:22:11+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=c440a5b814005c85ec903f9b9e44e25bf5c9c565'/>
<id>urn:sha1:c440a5b814005c85ec903f9b9e44e25bf5c9c565</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Add `ast::ExprKind::Dummy`</title>
<updated>2024-02-25T21:22:09+00:00</updated>
<author>
<name>Lieselotte</name>
<email>52315535+she3py@users.noreply.github.com</email>
</author>
<published>2024-02-25T21:22:09+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=a3fce72a27ee41077c3752851ff778f886f0a4fa'/>
<id>urn:sha1:a3fce72a27ee41077c3752851ff778f886f0a4fa</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Delegation implementation: step 1</title>
<updated>2024-01-12T11:11:16+00:00</updated>
<author>
<name>Bryanskiy</name>
<email>ivakin.kir@gmail.com</email>
</author>
<published>2023-11-26T12:57:31+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=d69cd6473c110096bb009db0f2f21da6f67ac5a6'/>
<id>urn:sha1:d69cd6473c110096bb009db0f2f21da6f67ac5a6</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Auto merge of #119105 - dtolnay:paren, r=WaffleLapkin</title>
<updated>2023-12-27T21:27:26+00:00</updated>
<author>
<name>bors</name>
<email>bors@rust-lang.org</email>
</author>
<published>2023-12-27T21:27:26+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=89e2160c4ca5808657ed55392620ed1dbbce78d1'/>
<id>urn:sha1:89e2160c4ca5808657ed55392620ed1dbbce78d1</id>
<content type='text'>
Fix parenthesization of subexprs containing statement boundary

This PR fixes a multitude of false negatives and false positives in the AST pretty printer's parenthesis insertion related to statement boundaries &amp;mdash; statements which terminate unexpectedly early if there aren't parentheses.

Without this fix, the AST pretty printer (including both `stringify!` and `rustc -Zunpretty=expanded`) is prone to producing output which is not syntactically valid Rust. Invalid output is problematic because it means Rustfmt is unable to parse the output of `cargo expand`, for example, causing friction by forcing someone trying to debug a macro into reading poorly formatted code.

I believe the set of bugs fixed in this PR account for the most prevalent reason that `cargo expand` produces invalid output in real-world usage.

Fixes #98790.

## False negatives

The following is a correct program &amp;mdash; `cargo check` succeeds.

```rust
macro_rules! m {
    ($e:expr) =&gt; {
        match () { _ =&gt; $e }
    };
}

fn main() {
    m!({ 1 } - 1);
}
```

But `rustc -Zunpretty=expanded main.rs` produces output that is invalid Rust syntax, because parenthesization is needed and not being done by the pretty printer.

```rust
fn main() { match () { _ =&gt; { 1 } - 1, }; }
```

Piping this expanded code to rustfmt, it fails to parse.

```console
error: unexpected `,` in pattern
 --&gt; &lt;stdin&gt;:1:38
  |
1 | fn main() { match () { _ =&gt; { 1 } - 1, }; }
  |                                      ^
  |
help: try adding parentheses to match on a tuple...
  |
1 | fn main() { match () { _ =&gt; { 1 } (- 1,) }; }
  |                                   +    +
help: ...or a vertical bar to match on multiple alternatives
  |
1 | fn main() { match () { _ =&gt; { 1 } - 1 | }; }
  |                                   ~~~~~
```

Fixed output after this PR:

```rust
fn main() { match () { _ =&gt; ({ 1 }) - 1, }; }
```

## False positives

Less problematic, but worth fixing (just like #118726).

```rust
fn main() {
    let _ = match () { _ =&gt; 1 } - 1;
}
```

Output of `rustc -Zunpretty=expanded lib.rs` before this PR. There is no reason parentheses would need to be inserted there.

```rust
fn main() { let _ = (match () { _ =&gt; 1, }) - 1; }
```

After this PR:

```rust
fn main() { let _ = match () { _ =&gt; 1, } - 1; }
```

## Alternatives considered

In this PR I opted to parenthesize only the leading subexpression causing the statement boundary, rather than the entire statement. Example:

```rust
macro_rules! m {
    ($e:expr) =&gt; {
        $e
    };
}

fn main() {
    m!(loop { break [1]; }[0] - 1);
}
```

This PR produces the following pretty-printed contents for fn main:

```rust
(loop { break [1]; })[0] - 1;
```

A different equally correct output would be:

```rust
(loop { break [1]; }[0] - 1);
```

I chose the one I did because it is the *only* approach used by handwritten code in the standard library and compiler. There are 4 places where parenthesization is being used to prevent a statement boundary, and in all 4, the developer has chosen to parenthesize the smallest subexpression rather than the whole statement:

https://github.com/rust-lang/rust/blob/b37d43efd9c5a7a3d76ed21c454dd0f40945d77d/compiler/rustc_codegen_cranelift/example/alloc_system.rs#L102

https://github.com/rust-lang/rust/blob/b37d43efd9c5a7a3d76ed21c454dd0f40945d77d/compiler/rustc_parse/src/errors.rs#L1021-L1029

https://github.com/rust-lang/rust/blob/b37d43efd9c5a7a3d76ed21c454dd0f40945d77d/library/core/src/future/poll_fn.rs#L151

https://github.com/rust-lang/rust/blob/b37d43efd9c5a7a3d76ed21c454dd0f40945d77d/library/core/src/ops/range.rs#L824-L828
</content>
</entry>
<entry>
<title>Rollup merge of #119169 - fmease:pretty-yeet-syntactic-cruft, r=compiler-errors</title>
<updated>2023-12-22T18:01:26+00:00</updated>
<author>
<name>Matthias Krüger</name>
<email>matthias.krueger@famsik.de</email>
</author>
<published>2023-12-22T18:01:26+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=15dc9f5bee8ba12df5545e8cd05215fb24f845ba'/>
<id>urn:sha1:15dc9f5bee8ba12df5545e8cd05215fb24f845ba</id>
<content type='text'>
Rid the AST &amp; HIR pretty printer of cruft

Found while working on #119163.

For `trait Trait: ?Sized {}` (semantically malformed), we currently output `trait Trait for ? Sized {}` (sic!) / `trait Trait for ? Sized { }` (sic!) if `-Zunpretty=expanded` / `-Zunpretty=hir` is passed.

`trait Tr for Sized? {}` (#15521) and later also `trait Tr for ?Sized {}` (I guess, #20194) is former Rust syntax. Hence I'm removing these outdated branches.

~~This will conflict with #119163, therefore marking this PR as blocked.~~ Rebased
</content>
</entry>
<entry>
<title>Auto merge of #118847 - eholk:for-await, r=compiler-errors</title>
<updated>2023-12-22T14:17:10+00:00</updated>
<author>
<name>bors</name>
<email>bors@rust-lang.org</email>
</author>
<published>2023-12-22T14:17:10+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=208dd2032b40ec3f1585dca0eacd7b0e542d22f5'/>
<id>urn:sha1:208dd2032b40ec3f1585dca0eacd7b0e542d22f5</id>
<content type='text'>
Add support for `for await` loops

This adds support for `for await` loops. This includes parsing, desugaring in AST-&gt;HIR lowering, and adding some support functions to the library.

Given a loop like:
```rust
for await i in iter {
    ...
}
```
this is desugared to something like:
```rust
let mut iter = iter.into_async_iter();
while let Some(i) = loop {
    match core::pin::Pin::new(&amp;mut iter).poll_next(cx) {
        Poll::Ready(i) =&gt; break i,
        Poll::Pending =&gt; yield,
    }
} {
    ...
}
```

This PR also adds a basic `IntoAsyncIterator` trait. This is partly for symmetry with the way `Iterator` and `IntoIterator` work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. `IntoAsyncIterator` gives us a good place to do this.

I've gated this feature behind `async_for_loop` and opened #118898 as the feature tracking issue.

r? `@compiler-errors`
</content>
</entry>
<entry>
<title>Rid the AST &amp; HIR pretty printers of syntactic cruft</title>
<updated>2023-12-22T13:32:40+00:00</updated>
<author>
<name>León Orell Valerian Liehr</name>
<email>me@fmease.dev</email>
</author>
<published>2023-12-20T19:27:23+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=b09889b959c00d43803113aeda24c2ff400f2caf'/>
<id>urn:sha1:b09889b959c00d43803113aeda24c2ff400f2caf</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Auto merge of #119163 - fmease:refactor-ast-trait-bound-modifiers, r=compiler-errors</title>
<updated>2023-12-22T02:00:55+00:00</updated>
<author>
<name>bors</name>
<email>bors@rust-lang.org</email>
</author>
<published>2023-12-22T02:00:55+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=aaef5fe4971c42bae088b18e765339f3ec8853d0'/>
<id>urn:sha1:aaef5fe4971c42bae088b18e765339f3ec8853d0</id>
<content type='text'>
Refactor AST trait bound modifiers

Instead of having two types to represent trait bound modifiers in the parser / the AST (`parser::ty::BoundModifiers` &amp; `ast::TraitBoundModifier`), only to map one to the other later, just use `parser::ty::BoundModifiers` (moved &amp; renamed to `ast::TraitBoundModifiers`).

The struct type is more extensible and easier to deal with (see [here](https://github.com/rust-lang/rust/pull/119099/files#r1430749981) and [here](https://github.com/rust-lang/rust/pull/119099/files#r1430752116) for context) since it more closely models what it represents: A compound of two kinds of modifiers, constness and polarity. Modeling this as an enum (the now removed `ast::TraitBoundModifier`) meant one had to add a new variant per *combination* of modifier kind, which simply isn't scalable and which lead to a lot of explicit non-DRY matches.

NB: `hir::TraitBoundModifier` being an enum is fine since HIR doesn't need to worry representing invalid modifier kind combinations as those get rejected during AST validation thereby immensely cutting down the number of possibilities.
</content>
</entry>
<entry>
<title>Refactor AST trait bound modifiers</title>
<updated>2023-12-20T18:39:46+00:00</updated>
<author>
<name>León Orell Valerian Liehr</name>
<email>me@fmease.dev</email>
</author>
<published>2023-12-20T14:22:06+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=5e4f12b41a13d6adf883cfeae8a17724ea457faf'/>
<id>urn:sha1:5e4f12b41a13d6adf883cfeae8a17724ea457faf</id>
<content type='text'>
</content>
</entry>
</feed>
