rust/tests/ui/unpretty
Matthias Krüger b12bb2530b
Rollup merge of #134847 - dtolnay:asymmetrical, r=fmease
Implement asymmetrical precedence for closures and jumps

I have been through a series of asymmetrical precedence designs in Syn, and finally have one that I like and is worth backporting into rustc. It is based on just 2 bits of state: `next_operator_can_begin_expr` and `next_operator_can_continue_expr`.

Asymmetrical precedence is the thing that enables `(return 1) + 1` to require parentheses while `1 + return 1` does not, despite `+` always having stronger precedence than `return` [according to the Rust Reference](https://doc.rust-lang.org/1.83.0/reference/expressions.html#expression-precedence). This is facilitated by `next_operator_can_continue_expr`.

Relatedly, it is the thing that enables `(return) - 1` to require parentheses while `return + 1` does not, despite `+` and `-` having exactly the same precedence. This is facilitated by `next_operator_can_begin_expr`.

**Example:**

```rust
macro_rules! repro {
    ($e:expr) => {
        $e - $e;
        $e + $e;
    };
}

fn main() {
    repro!{return}
    repro!{return 1}
}
```

`-Zunpretty=expanded` **Before:**

```console
fn main() {
    (return) - (return);
    (return) + (return);
    (return 1) - (return 1);
    (return 1) + (return 1);
}
```

**After:**

```console
fn main() {
    (return) - return;
    return + return;
    (return 1) - return 1;
    (return 1) + return 1;
}
```
2025-06-13 05:16:54 +02:00
..
auxiliary Add tests for -Zunpretty=expanded ported from stringify's tests 2024-05-18 10:36:02 -07:00
ast-const-trait-bound.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
ast-const-trait-bound.stdout [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
avoid-crash.rs compiletest: Support matching on diagnostics without a span 2025-03-25 17:33:09 +03:00
avoid-crash.stderr Fix unpretty UI test when /tmp does not exist 2024-03-24 14:00:45 +00:00
bad-literal.rs Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
bad-literal.stderr Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
bad-literal.stdout Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
box.rs turn rustc_box into an intrinsic 2025-01-03 12:01:31 +01:00
box.stdout turn rustc_box into an intrinsic 2025-01-03 12:01:31 +01:00
debug-fmt-hir.rs Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
debug-fmt-hir.stdout Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
deprecated-attr.rs Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
deprecated-attr.stdout Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
diagnostic-attr.rs Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
diagnostic-attr.stdout Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
exhaustive-asm.expanded.stdout Improve coverage of HIR pretty printing. 2025-05-02 12:41:02 +10:00
exhaustive-asm.hir.stdout Fix hir pretty-printing of global_asm!. 2025-05-03 09:14:27 +10:00
exhaustive-asm.rs Improve coverage of HIR pretty printing. 2025-05-02 12:41:02 +10:00
exhaustive.expanded.stdout Implement asymmetrical precedence for closures and jumps 2025-05-03 23:27:29 -07:00
exhaustive.hir.stderr Improve coverage of HIR pretty printing. 2025-05-02 12:41:02 +10:00
exhaustive.hir.stdout Avoid an indent for labelled loops. 2025-05-03 12:46:51 +10:00
exhaustive.rs Improve coverage of HIR pretty printing. 2025-05-02 12:41:02 +10:00
extern-static.rs Print safety correctly in extern static items 2024-10-24 00:41:27 +00:00
extern-static.stdout Print safety correctly in extern static items 2024-10-24 00:41:27 +00:00
flattened-format-args.rs Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
flattened-format-args.stdout Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
hir-tree.rs compiletest: Support matching on non-json lines in compiler output 2025-05-04 18:27:45 +03:00
interpolation-expanded.rs Improve coverage of HIR pretty printing. 2025-05-02 12:41:02 +10:00
interpolation-expanded.stdout Improve coverage of HIR pretty printing. 2025-05-02 12:41:02 +10:00
let-else-hir.rs Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
let-else-hir.stdout Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
mir-unpretty.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
mir-unpretty.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
self-hir.rs Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
self-hir.stdout Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
staged-api-invalid-path-108697.rs Fix test that relies on error language 2025-02-16 09:08:24 +00:00
staged-api-invalid-path-108697.stderr Fix test that relies on error language 2025-02-16 09:08:24 +00:00
unpretty-expr-fn-arg.rs Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
unpretty-expr-fn-arg.stdout Explicitly annotate edition for unpretty=expanded and unpretty=hir tests 2025-04-16 11:10:10 +02:00
unsafe-attr.rs Add AST unpretty test for unsafe attribute 2024-10-26 13:31:24 +02:00
unsafe-attr.stdout Print unsafety of attribute in AST unpretty 2024-10-26 13:33:36 +02:00