Add wrapper type for tokenizing passthrough attrs
diff --git a/syntax/attrs.rs b/syntax/attrs.rs
index 7f50dcb..0d00f22 100644
--- a/syntax/attrs.rs
+++ b/syntax/attrs.rs
@@ -2,7 +2,8 @@
use crate::syntax::report::Errors;
use crate::syntax::Atom::{self, *};
use crate::syntax::{Derive, Doc};
-use proc_macro2::Ident;
+use proc_macro2::{Ident, TokenStream};
+use quote::ToTokens;
use syn::parse::{ParseStream, Parser as _};
use syn::{Attribute, Error, LitStr, Path, Result, Token};
@@ -39,7 +40,7 @@
pub(crate) _more: (),
}
-pub(super) fn parse(cx: &mut Errors, attrs: Vec<Attribute>, mut parser: Parser) -> Vec<Attribute> {
+pub(super) fn parse(cx: &mut Errors, attrs: Vec<Attribute>, mut parser: Parser) -> OtherAttrs {
let mut passthrough_attrs = Vec::new();
for attr in attrs {
if attr.path.is_ident("doc") {
@@ -132,7 +133,7 @@
cx.error(attr, "unsupported attribute");
break;
}
- passthrough_attrs
+ OtherAttrs(passthrough_attrs)
}
fn parse_doc_attribute(input: ParseStream) -> Result<LitStr> {
@@ -189,3 +190,19 @@
input.parse()
}
}
+
+pub struct OtherAttrs(Vec<Attribute>);
+
+impl OtherAttrs {
+ pub fn none() -> Self {
+ OtherAttrs(Vec::new())
+ }
+}
+
+impl ToTokens for OtherAttrs {
+ fn to_tokens(&self, tokens: &mut TokenStream) {
+ for attr in &self.0 {
+ attr.to_tokens(tokens);
+ }
+ }
+}
diff --git a/syntax/mod.rs b/syntax/mod.rs
index c478d3c..da21204 100644
--- a/syntax/mod.rs
+++ b/syntax/mod.rs
@@ -25,6 +25,7 @@
pub mod trivial;
pub mod types;
+use self::attrs::OtherAttrs;
use self::discriminant::Discriminant;
use self::namespace::Namespace;
use self::parse::kw;
@@ -32,7 +33,7 @@
use proc_macro2::{Ident, Span};
use syn::punctuated::Punctuated;
use syn::token::{Brace, Bracket, Paren};
-use syn::{Attribute, Expr, Generics, Lifetime, LitInt, Token, Type as RustType};
+use syn::{Expr, Generics, Lifetime, LitInt, Token, Type as RustType};
pub use self::atom::Atom;
pub use self::derive::{Derive, Trait};
@@ -72,7 +73,7 @@
pub lang: Lang,
pub doc: Doc,
pub derives: Vec<Derive>,
- pub attrs: Vec<Attribute>,
+ pub attrs: OtherAttrs,
pub type_token: Token![type],
pub name: Pair,
pub generics: Lifetimes,
@@ -85,7 +86,7 @@
pub struct Struct {
pub doc: Doc,
pub derives: Vec<Derive>,
- pub attrs: Vec<Attribute>,
+ pub attrs: OtherAttrs,
pub visibility: Token![pub],
pub struct_token: Token![struct],
pub name: Pair,
@@ -96,7 +97,7 @@
pub struct Enum {
pub doc: Doc,
pub derives: Vec<Derive>,
- pub attrs: Vec<Attribute>,
+ pub attrs: OtherAttrs,
pub enum_token: Token![enum],
pub name: Pair,
pub brace_token: Brace,
@@ -109,7 +110,7 @@
pub struct ExternFn {
pub lang: Lang,
pub doc: Doc,
- pub attrs: Vec<Attribute>,
+ pub attrs: OtherAttrs,
pub name: Pair,
pub sig: Signature,
pub semi_token: Token![;],
@@ -119,7 +120,7 @@
pub struct TypeAlias {
pub doc: Doc,
pub derives: Vec<Derive>,
- pub attrs: Vec<Attribute>,
+ pub attrs: OtherAttrs,
pub type_token: Token![type],
pub name: Pair,
pub generics: Lifetimes,
@@ -156,7 +157,7 @@
pub struct Var {
pub doc: Doc,
- pub attrs: Vec<Attribute>,
+ pub attrs: OtherAttrs,
pub visibility: Token![pub],
pub ident: Ident,
pub ty: Type,
@@ -176,7 +177,7 @@
pub struct Variant {
pub doc: Doc,
- pub attrs: Vec<Attribute>,
+ pub attrs: OtherAttrs,
pub name: Pair,
pub discriminant: Discriminant,
pub expr: Option<Expr>,
diff --git a/syntax/parse.rs b/syntax/parse.rs
index 87f43b2..5ce2cf3 100644
--- a/syntax/parse.rs
+++ b/syntax/parse.rs
@@ -1,3 +1,4 @@
+use crate::syntax::attrs::OtherAttrs;
use crate::syntax::discriminant::DiscriminantSet;
use crate::syntax::file::{Item, ItemForeignMod};
use crate::syntax::report::Errors;
@@ -544,7 +545,7 @@
let ty = parse_type(&arg.ty)?;
if ident != "self" {
let doc = Doc::new();
- let attrs = Vec::new();
+ let attrs = OtherAttrs::none();
let visibility = Token);
args.push_value(Var {
doc,
@@ -1122,7 +1123,7 @@
None => format_ident!("arg{}", i),
};
let doc = Doc::new();
- let attrs = Vec::new();
+ let attrs = OtherAttrs::none();
let visibility = Token);
Ok(Var {
doc,