about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2024-12-27 18:43:05 -0800
committerGitHub <noreply@github.com>2024-12-27 18:43:05 -0800
commit3fc0f08b8988e8864effd2ccaa6187df524e892e (patch)
treedd392a797a32bb1a90d49d2938eb3e5a2bff40ca /compiler/rustc_codegen_llvm/src
parent2d96f2a48fb825e2028c1ee45f3a4ebd941ff8e2 (diff)
parente67fe3698bfd0f3957abb84c2b396c50822a5b67 (diff)
downloadrust-3fc0f08b8988e8864effd2ccaa6187df524e892e.tar.gz
rust-3fc0f08b8988e8864effd2ccaa6187df524e892e.zip
Rollup merge of #134833 - dtolnay:leftmostwithdot, r=compiler-errors
Skip parenthesis if `.` makes statement boundary unambiguous

There is a rule in the parser that statements and match-arms never end in front of a `.` or `?` token (except when the `.` is really `..` or `..=` or `...`). So some of the leading subexpressions that need parentheses inserted when followed by some other operator like `-` or `+`, do not need parentheses when followed by `.` or `?`.

Example:

```rust
fn main() {
    loop {}.to_string() + "";
    match () {
        _ => loop {}.to_string() + "",
    };
}
```

`-Zunpretty=expanded` before:

```console
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
fn main() {
    (loop {}).to_string() + "";
    match () { _ => (loop {}).to_string() + "", };
}
```

After:

```console
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
fn main() {
    loop {}.to_string() + "";
    match () { _ => loop {}.to_string() + "", };
}
```
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
0 files changed, 0 insertions, 0 deletions