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
    ------------------------------------------
This commit is contained in:
David Tolnay 2025-06-13 12:51:07 -07:00
parent 1ed0cbf698
commit cbef8f6e07
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82

View file

@ -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",