Repository: dtolnay/cxx (language: rust)

Issue:
Bridge attribute breaks inner attributes
```rust
#[cxx::bridge]
mod ffi {
    #![deny(missing_docs)]

    unsafe extern "C++" {
        include!("example/include/header.h");

        /// wow
        fn f();
    }
}

pub use self::ffi::*;
```

```console
error: an inner attribute is not permitted in this context
 --> src/main.rs:3:5
  |
3 |     #![deny(missing_docs)]
  |     ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.
```

Probably what's going wrong is we are accidentally transporting the inner attributes out to outside of the corresponding item in the macro output, which is not where they are supposed to go.


Discussion / hints:

Fix patch:
diff --git a/syntax/attrs.rs b/syntax/attrs.rs
index 4808f2e1e..0ced368d5 100644
--- a/syntax/attrs.rs
+++ b/syntax/attrs.rs
@@ -224,7 +224,19 @@ impl OtherAttrs {
 impl ToTokens for OtherAttrs {
     fn to_tokens(&self, tokens: &mut TokenStream) {
         for attr in &self.0 {
-            attr.to_tokens(tokens);
+            let Attribute {
+                pound_token,
+                style,
+                bracket_token,
+                path,
+                tokens: attr_tokens,
+            } = attr;
+            pound_token.to_tokens(tokens);
+            let _ = style; // ignore; render outer and inner attrs both as outer
+            bracket_token.surround(tokens, |tokens| {
+                path.to_tokens(tokens);
+                attr_tokens.to_tokens(tokens);
+            });
         }
     }
 }


Test patch: