about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/errors.rs
diff options
context:
space:
mode:
authorTrevor Gross <t.gross35@gmail.com>2025-06-20 23:25:54 -0400
committerGitHub <noreply@github.com>2025-06-20 23:25:54 -0400
commit8751016e20ff13f36327ec1527448522e8dc7247 (patch)
treeda47621c53d9d5bdf65a28d8b013c45ea06e6816 /compiler/rustc_codegen_llvm/src/errors.rs
parent7b355110dffbd25e5416edc06cc75612eb81323e (diff)
parent535e11f72e0c2460fac74aa0625b47fb0ff43ec6 (diff)
downloadrust-8751016e20ff13f36327ec1527448522e8dc7247.tar.gz
rust-8751016e20ff13f36327ec1527448522e8dc7247.zip
Rollup merge of #142476 - dtolnay:attrbinop, r=fmease
Insert parentheses around binary operation with attribute

Fixes the bug found by `@fmease` in https://github.com/rust-lang/rust/pull/134661#pullrequestreview-2538983253.

Previously, `-Zunpretty=expanded` would expand this program as follows:

```rust
#![feature(stmt_expr_attributes)]
#![allow(unused_attributes)]

macro_rules! group {
    ($e:expr) => {
        $e
    };
}

macro_rules! extra {
    ($e:expr) => {
        #[allow()] $e
    };
}

fn main() {
    let _ = #[allow()] 1 + 1;
    let _ = group!(#[allow()] 1) + 1;
    let _ = 1 + group!(#[allow()] 1);
    let _ = extra!({ 0 }) + 1;
    let _ = extra!({ 0 } + 1);
}
```

```console
let _ = #[allow()] 1 + 1;
let _ = #[allow()] 1 + 1;
let _ = 1 + #[allow()] 1;
let _ = #[allow()] { 0 } + 1;
let _ = #[allow()] { 0 } + 1;
```

The first 4 statements are the correct expansion, but the last one is not. The attribute is supposed to apply to the entire binary operation, not only to the left operand.

After this PR, the 5th statement will expand to:

```console
let _ = #[allow()] ({ 0 } + 1);
```

In the future, as some subset of `stmt_expr_attributes` approaches stabilization, it is possible that we will need to do parenthesization for a number of additional cases depending on the outcome of https://github.com/rust-lang/rust/issues/127436. But for now, at least this PR makes the pretty-printer align with the current behavior of the parser.

r? fmease
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/errors.rs')
0 files changed, 0 insertions, 0 deletions