Skip to content

Commit

Permalink
Rollup merge of #92412 - dtolnay:tryspace, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Fix double space in pretty printed TryBlock

Follow-up to #92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($expr:expr) => {
        stringify!($expr)
    };
}

fn main() {
    println!("{}", repro!(try {}));
}
```

Before:&ensp;<code>try&nbsp;&nbsp;{}</code>
After:&ensp;<code>try&nbsp;{}</code>

The `head` helper already appends a space:

https://github.com/rust-lang/rust/blob/2b67c30bfece00357d5fc09d99b49f21066f04ba/compiler/rustc_ast_pretty/src/pprust/state.rs#L654-L664

so doing `head` followed by `space` resulted in a double space:

https://github.com/rust-lang/rust/blob/2b67c30bfece00357d5fc09d99b49f21066f04ba/compiler/rustc_ast_pretty/src/pprust/state.rs#L2241-L2242
  • Loading branch information
matthiaskrgr authored Jan 1, 2022
2 parents a6e4d68 + 2f25a4a commit 682b4cb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 2 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2241,7 +2241,6 @@ impl<'a> State<'a> {
}
ast::ExprKind::TryBlock(ref blk) => {
self.head("try");
self.space();
self.print_block_with_attrs(blk, attrs)
}
ast::ExprKind::Err => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/macros/stringify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ fn test_expr() {
assert_eq!(stringify_expr!(expr.await), "expr.await");

// ExprKind::TryBlock
assert_eq!(stringify_expr!(try {}), "try {}"); // FIXME
assert_eq!(stringify_expr!(try {}), "try {}");

// ExprKind::Assign
assert_eq!(stringify_expr!(expr = true), "expr = true");
Expand Down

0 comments on commit 682b4cb

Please sign in to comment.