Repository: dtolnay/syn (rust)

Issue:
Attribute on binary expression
https://github.com/rust-lang/rust/blob/46e85b4328fe18492894093c1092dfe509df4370/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs#L17-L20 currently fails our roundtrip test on this part:

```rust
fn skip_on_statements() {
    #[cfg_attr(rustfmt, rustfmt::skip)]
    5+3;
}
```

Pull request description:
Fix precedence of attributes on binary expression
Closes #820. I don't know the exact rules but this passes the precedence test.

Patch:
diff --git a/src/stmt.rs b/src/stmt.rs
index a3765d58..2b25edb4 100644
--- a/src/stmt.rs
+++ b/src/stmt.rs
@@ -252,8 +252,12 @@ pub mod parsing {
     ) -> Result<Stmt> {
         let mut e = expr::parsing::expr_early(input)?;
 
-        attrs.extend(e.replace_attrs(Vec::new()));
-        e.replace_attrs(attrs);
+        let mut attr_target = &mut e;
+        while let Expr::Binary(e) = attr_target {
+            attr_target = &mut e.left;
+        }
+        attrs.extend(attr_target.replace_attrs(Vec::new()));
+        attr_target.replace_attrs(attrs);
 
         if input.peek(Token![;]) {
             return Ok(Stmt::Semi(e, input.parse()?));


Test patch:
diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs
index ddb63684..5d8f8e93 100644
--- a/tests/repo/mod.rs
+++ b/tests/repo/mod.rs
@@ -11,10 +11,6 @@ use walkdir::DirEntry;
 const REVISION: &str = "46e85b4328fe18492894093c1092dfe509df4370";
 
 static EXCLUDE: &[&str] = &[
-    // TODO: attribute on binary expr
-    // https://github.com/dtolnay/syn/issues/820
-    "tools/clippy/tests/ui/cfg_attr_rustfmt.rs",
-
     // TODO: type alias item with trait bound
     // https://github.com/dtolnay/syn/issues/821
     "test/ui/parser/item-free-type-bounds-syntactic-pass.rs",