Reduce precedence of expressions that have an outer attr by dtolnay · Pull Request #134661 · rust-lang/rust (original) (raw)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ExprPrecedence::Prefix isn't low enough. Consider the following cases involving binops:

#![feature(stmt_expr_attributes)]

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

fn main() { // -Zunpretty=expanded on master & prefixattr:

let _ = #[allow()] 1 + 1;           // let _ = #[allow()] 1 + 1;
let _ = group!(#[allow()] 1) + 1;   // let _ = #[allow()] 1 + 1;
let _ = 1 + group!(#[allow()] 1);   // let _ = 1 + #[allow()] 1;

let _ = extra!({ 0 }) + 1;          // let _ = #[allow()] { 0 } + 1;
let _ = extra!({ 0 } + 1);          // let _ = #[allow()] { 0 } + 1;

}

I haven't given it that much thought yet, so I don't know which specific precedence level(s) would make sense instead.

And indeed, this example is heavily inspired by the ones found in #15701 / #127436. So maybe answering this pretty-printing question is partially blocked by the open design question (meaning we can ignore it for now).