about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2025-06-13 12:51:07 -0700
committerDavid Tolnay <dtolnay@gmail.com>2025-06-20 13:49:12 -0700
commitcbef8f6e0745e7ee5bcd91a482a3152a2b1dd23b (patch)
treea04466ec579905931a75f618b8364a029e730d87
parent1ed0cbf698bbed4135eb4e47c4ac22a907dd41e9 (diff)
downloadrust-cbef8f6e0745e7ee5bcd91a482a3152a2b1dd23b.tar.gz
rust-cbef8f6e0745e7ee5bcd91a482a3152a2b1dd23b.zip
Add AST pretty-printer tests involving attr on binary operation
This test currently fails (as expected).

    --- stderr -------------------------------
    Pretty-printer lost necessary parentheses
      BEFORE: #[attr] (1 + 1)
       AFTER: #[attr] 1 + 1

    Pretty-printer lost necessary parentheses
      BEFORE: #[attr] (1 as T)
       AFTER: #[attr] 1 as T

    Pretty-printer lost necessary parentheses
      BEFORE: #[attr] (x = 1)
       AFTER: #[attr] x = 1

    Pretty-printer lost necessary parentheses
      BEFORE: #[attr] (x += 1)
       AFTER: #[attr] x += 1
    ------------------------------------------
-rw-r--r--tests/ui-fulldeps/pprust-parenthesis-insertion.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs
index 6ac079ae434..346b8ed5fda 100644
--- a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs
+++ b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs
@@ -92,6 +92,15 @@ static EXPRS: &[&str] = &[
     "#[attr] loop {}.field",
     "(#[attr] loop {}).field",
     "loop { #![attr] }.field",
+    // Attributes on a Binary, Cast, Assign, AssignOp, and Range expression
+    // require parentheses. Without parentheses `#[attr] lo..hi` means
+    // `(#[attr] lo)..hi`, and `#[attr] ..hi` is invalid syntax.
+    "#[attr] (1 + 1)",
+    "#[attr] (1 as T)",
+    "#[attr] (x = 1)",
+    "#[attr] (x += 1)",
+    "#[attr] (lo..hi)",
+    "#[attr] (..hi)",
     // Grammar restriction: break value starting with a labeled loop is not
     // allowed, except if the break is also labeled.
     "break 'outer 'inner: loop {} + 2",