Rewrite codegen
The primary purpose is to split up parsing the `syn` source from
generating visit / visit_mut / fold.
The commit defines an intermediate representation of syn's internal
types. The first step is then to parse the syn source and construct the
intermediate representation. Then, code is generated using the IR.
This change is a precursor to generating a JSON version of the IR.
diff --git a/codegen/src/gen.rs b/codegen/src/gen.rs
new file mode 100644
index 0000000..9f622b9
--- /dev/null
+++ b/codegen/src/gen.rs
@@ -0,0 +1,779 @@
+//! This crate automatically generates the definition of the `Visit`,
+//! `VisitMut`, and `Fold` traits in `syn` based on the `syn` source. It
+//! discovers structs and enums declared with the `ast_*` macros and generates
+//! the functions for those types.
+//!
+//! It makes a few assumptions about the target crate:
+//! 1. All structs which are discovered must be re-exported in the root of the
+//! crate, even if they were declared in a submodule.
+//! 2. This code cannot discover submodules which are located in subdirectories
+//! - only submodules located in the same directory.
+//! 3. The path to `syn` is hardcoded.
+
+use crate::types;
+use proc_macro2::TokenStream;
+
+use std::fs::File;
+use std::io::Write;
+
+const FOLD_SRC: &str = "../src/gen/fold.rs";
+const VISIT_SRC: &str = "../src/gen/visit.rs";
+const VISIT_MUT_SRC: &str = "../src/gen/visit_mut.rs";
+
+mod codegen {
+ use crate::types;
+ use inflections::Inflect;
+ use proc_macro2::{Span, TokenStream};
+ use quote::TokenStreamExt;
+ use syn::*;
+
+ #[derive(Default)]
+ pub struct State {
+ pub visit_trait: TokenStream,
+ pub visit_impl: TokenStream,
+ pub visit_mut_trait: TokenStream,
+ pub visit_mut_impl: TokenStream,
+ pub fold_trait: TokenStream,
+ pub fold_impl: TokenStream,
+ }
+
+ fn under_name(name: &str) -> Ident {
+ Ident::new(&name.to_snake_case(), Span::call_site())
+ }
+
+ #[derive(Debug, Eq, PartialEq, Copy, Clone)]
+ enum Kind {
+ Visit,
+ VisitMut,
+ Fold,
+ }
+
+ enum Operand {
+ Borrowed(TokenStream),
+ Owned(TokenStream),
+ }
+
+ use self::Kind::*;
+ use self::Operand::*;
+
+ impl Operand {
+ fn tokens(&self) -> &TokenStream {
+ match *self {
+ Borrowed(ref n) | Owned(ref n) => n,
+ }
+ }
+
+ fn ref_tokens(&self) -> TokenStream {
+ match *self {
+ Borrowed(ref n) => n.clone(),
+ Owned(ref n) => quote!(&#n),
+ }
+ }
+
+ fn ref_mut_tokens(&self) -> TokenStream {
+ match *self {
+ Borrowed(ref n) => n.clone(),
+ Owned(ref n) => quote!(&mut #n),
+ }
+ }
+
+ fn owned_tokens(&self) -> TokenStream {
+ match *self {
+ Borrowed(ref n) => quote!(*#n),
+ Owned(ref n) => n.clone(),
+ }
+ }
+ }
+
+ fn simple_visit(item: &str, kind: Kind, name: &Operand) -> TokenStream {
+ let ident = under_name(item);
+
+ match kind {
+ Visit => {
+ let method = Ident::new(&format!("visit_{}", ident), Span::call_site());
+ let name = name.ref_tokens();
+ quote! {
+ _visitor.#method(#name)
+ }
+ }
+ VisitMut => {
+ let method = Ident::new(&format!("visit_{}_mut", ident), Span::call_site());
+ let name = name.ref_mut_tokens();
+ quote! {
+ _visitor.#method(#name)
+ }
+ }
+ Fold => {
+ let method = Ident::new(&format!("fold_{}", ident), Span::call_site());
+ let name = name.owned_tokens();
+ quote! {
+ _visitor.#method(#name)
+ }
+ }
+ }
+ }
+
+ fn box_visit(
+ elem: &types::Type,
+ features: &types::Features,
+ types: &[types::TypeDef],
+ kind: Kind,
+ name: &Operand,
+ ) -> Option<TokenStream> {
+ let name = name.owned_tokens();
+ let res = visit(elem, features, types, kind, &Owned(quote!(*#name)))?;
+ Some(match kind {
+ Fold => quote! {
+ Box::new(#res)
+ },
+ Visit | VisitMut => res,
+ })
+ }
+
+ fn vec_visit(
+ elem: &types::Type,
+ features: &types::Features,
+ types: &[types::TypeDef],
+ kind: Kind,
+ name: &Operand,
+ ) -> Option<TokenStream> {
+ let operand = match kind {
+ Visit | VisitMut => Borrowed(quote!(it)),
+ Fold => Owned(quote!(it)),
+ };
+ let val = visit(elem, features, types, kind, &operand)?;
+ Some(match kind {
+ Visit => {
+ let name = name.ref_tokens();
+ quote! {
+ for it in #name {
+ #val
+ }
+ }
+ }
+ VisitMut => {
+ let name = name.ref_mut_tokens();
+ quote! {
+ for it in #name {
+ #val
+ }
+ }
+ }
+ Fold => {
+ let name = name.owned_tokens();
+ quote! {
+ FoldHelper::lift(#name, |it| { #val })
+ }
+ }
+ })
+ }
+
+ fn punctuated_visit(
+ elem: &types::Type,
+ features: &types::Features,
+ types: &[types::TypeDef],
+ kind: Kind,
+ name: &Operand,
+ ) -> Option<TokenStream> {
+ let operand = match kind {
+ Visit | VisitMut => Borrowed(quote!(it)),
+ Fold => Owned(quote!(it)),
+ };
+ let val = visit(elem, features, types, kind, &operand)?;
+ Some(match kind {
+ Visit => {
+ let name = name.ref_tokens();
+ quote! {
+ for el in Punctuated::pairs(#name) {
+ let it = el.value();
+ #val
+ }
+ }
+ }
+ VisitMut => {
+ let name = name.ref_mut_tokens();
+ quote! {
+ for mut el in Punctuated::pairs_mut(#name) {
+ let it = el.value_mut();
+ #val
+ }
+ }
+ }
+ Fold => {
+ let name = name.owned_tokens();
+ quote! {
+ FoldHelper::lift(#name, |it| { #val })
+ }
+ }
+ })
+ }
+
+ fn option_visit(
+ elem: &types::Type,
+ features: &types::Features,
+ types: &[types::TypeDef],
+ kind: Kind,
+ name: &Operand,
+ ) -> Option<TokenStream> {
+ let it = match kind {
+ Visit | VisitMut => Borrowed(quote!(it)),
+ Fold => Owned(quote!(it)),
+ };
+ let val = visit(elem, features, types, kind, &it)?;
+ let name = name.owned_tokens();
+ Some(match kind {
+ Visit => quote! {
+ if let Some(ref it) = #name {
+ #val
+ }
+ },
+ VisitMut => quote! {
+ if let Some(ref mut it) = #name {
+ #val
+ }
+ },
+ Fold => quote! {
+ (#name).map(|it| { #val })
+ },
+ })
+ }
+
+ fn tuple_visit(
+ elems: &[types::Type],
+ features: &types::Features,
+ types: &[types::TypeDef],
+ kind: Kind,
+ name: &Operand,
+ ) -> Option<TokenStream> {
+ if elems.is_empty() {
+ return None;
+ }
+
+ let mut code = TokenStream::new();
+ for (i, elem) in elems.iter().enumerate() {
+ let name = name.tokens();
+ let i = Index::from(i);
+ let it = Owned(quote!((#name).#i));
+ let val =
+ visit(elem, features, types, kind, &it).unwrap_or_else(|| noop_visit(kind, &it));
+ code.append_all(val);
+ match kind {
+ Fold => code.append_all(quote!(,)),
+ Visit | VisitMut => code.append_all(quote!(;)),
+ }
+ }
+ Some(match kind {
+ Fold => quote! {
+ (#code)
+ },
+ Visit | VisitMut => code,
+ })
+ }
+
+ fn token_punct_visit(token: &types::Token, kind: Kind, name: &Operand) -> TokenStream {
+ let ty: TokenStream = syn::parse_str(&format!("Token![{}]", token.repr())).unwrap();
+ let name = name.tokens();
+ match kind {
+ Fold => quote! {
+ #ty(tokens_helper(_visitor, &#name.spans))
+ },
+ Visit => quote! {
+ tokens_helper(_visitor, &#name.spans)
+ },
+ VisitMut => quote! {
+ tokens_helper(_visitor, &mut #name.spans)
+ },
+ }
+ }
+
+ fn token_keyword_visit(token: &types::Token, kind: Kind, name: &Operand) -> TokenStream {
+ let ty: TokenStream = syn::parse_str(&format!("Token![{}]", token.repr())).unwrap();
+ let name = name.tokens();
+ match kind {
+ Fold => quote! {
+ #ty(tokens_helper(_visitor, &#name.span))
+ },
+ Visit => quote! {
+ tokens_helper(_visitor, &#name.span)
+ },
+ VisitMut => quote! {
+ tokens_helper(_visitor, &mut #name.span)
+ },
+ }
+ }
+
+ fn token_group_visit(ty: &str, kind: Kind, name: &Operand) -> TokenStream {
+ let ty = Ident::new(ty, Span::call_site());
+ let name = name.tokens();
+ match kind {
+ Fold => quote! {
+ #ty(tokens_helper(_visitor, &#name.span))
+ },
+ Visit => quote! {
+ tokens_helper(_visitor, &#name.span)
+ },
+ VisitMut => quote! {
+ tokens_helper(_visitor, &mut #name.span)
+ },
+ }
+ }
+
+ fn noop_visit(kind: Kind, name: &Operand) -> TokenStream {
+ match kind {
+ Fold => name.owned_tokens(),
+ Visit | VisitMut => {
+ let name = name.tokens();
+ quote! {
+ skip!(#name)
+ }
+ }
+ }
+ }
+
+ fn visit(
+ ty: &types::Type,
+ features: &types::Features,
+ types: &[types::TypeDef],
+ kind: Kind,
+ name: &Operand,
+ ) -> Option<TokenStream> {
+ match ty {
+ types::Type::Box(t) => box_visit(&*t, features, types, kind, name),
+ types::Type::Vec(t) => vec_visit(&*t, features, types, kind, name),
+ types::Type::Punctuated(t, _) => punctuated_visit(&*t, features, types, kind, name),
+ types::Type::Option(t) => option_visit(&*t, features, types, kind, name),
+ types::Type::Tuple(t) => tuple_visit(t, features, types, kind, name),
+ types::Type::Token(t) => {
+ if t.is_keyword() {
+ Some(token_keyword_visit(t, kind, name))
+ } else {
+ Some(token_punct_visit(t, kind, name))
+ }
+ }
+ types::Type::TokenGroup(t) => Some(token_group_visit(&t[..], kind, name)),
+ types::Type::Item(t) => {
+ fn requires_full(features: &types::Features) -> bool {
+ features.contains("full") && features.len() == 1
+ }
+
+ let mut res = simple_visit(t, kind, name);
+
+ let target = types.iter().find(|ty| ty.ident() == t).unwrap();
+
+ Some(
+ if requires_full(target.features()) && !requires_full(features) {
+ quote! {
+ full!(#res)
+ }
+ } else {
+ res
+ },
+ )
+ }
+ types::Type::Ext(_) | types::Type::Std(_) => None,
+ }
+ }
+
+ fn visit_features(features: &types::Features) -> TokenStream {
+ match features.len() {
+ 0 => quote!(),
+ 1 => {
+ let feature = &features[0];
+ quote!(#[cfg(feature = #feature)])
+ }
+ _ => {
+ let features = features.iter().map(|feature| quote!(feature = #feature));
+
+ quote!(#[cfg(any( #(#features),* ))])
+ }
+ }
+ }
+
+ pub fn generate(state: &mut State, s: &types::TypeDef, types: &[types::TypeDef]) {
+ let features = visit_features(s.features());
+ let under_name = under_name(s.ident());
+ let ty = Ident::new(s.ident(), Span::call_site());
+ let visit_fn = Ident::new(&format!("visit_{}", under_name), Span::call_site());
+ let visit_mut_fn = Ident::new(&format!("visit_{}_mut", under_name), Span::call_site());
+ let fold_fn = Ident::new(&format!("fold_{}", under_name), Span::call_site());
+
+ let mut visit_impl = TokenStream::new();
+ let mut visit_mut_impl = TokenStream::new();
+ let mut fold_impl = TokenStream::new();
+
+ match s {
+ types::TypeDef::Enum(ref e) => {
+ let mut visit_variants = TokenStream::new();
+ let mut visit_mut_variants = TokenStream::new();
+ let mut fold_variants = TokenStream::new();
+
+ for variant in e.variants() {
+ let variant_ident = Ident::new(variant.ident(), Span::call_site());
+
+ if variant.fields().is_empty() {
+ visit_variants.append_all(quote! {
+ #ty::#variant_ident => {}
+ });
+ visit_mut_variants.append_all(quote! {
+ #ty::#variant_ident => {}
+ });
+ fold_variants.append_all(quote! {
+ #ty::#variant_ident => {
+ #ty::#variant_ident
+ }
+ });
+ } else {
+ let mut bind_visit_fields = TokenStream::new();
+ let mut bind_visit_mut_fields = TokenStream::new();
+ let mut bind_fold_fields = TokenStream::new();
+
+ let mut visit_fields = TokenStream::new();
+ let mut visit_mut_fields = TokenStream::new();
+ let mut fold_fields = TokenStream::new();
+
+ for (idx, ty) in variant.fields().iter().enumerate() {
+ let name = format!("_binding_{}", idx);
+ let binding = Ident::new(&name, Span::call_site());
+
+ bind_visit_fields.append_all(quote! {
+ ref #binding,
+ });
+ bind_visit_mut_fields.append_all(quote! {
+ ref mut #binding,
+ });
+ bind_fold_fields.append_all(quote! {
+ #binding,
+ });
+
+ let borrowed_binding = Borrowed(quote!(#binding));
+ let owned_binding = Owned(quote!(#binding));
+
+ visit_fields.append_all(
+ visit(ty, s.features(), types, Visit, &borrowed_binding)
+ .unwrap_or_else(|| noop_visit(Visit, &borrowed_binding)),
+ );
+ visit_mut_fields.append_all(
+ visit(ty, s.features(), types, VisitMut, &borrowed_binding)
+ .unwrap_or_else(|| noop_visit(VisitMut, &borrowed_binding)),
+ );
+ fold_fields.append_all(
+ visit(ty, s.features(), types, Fold, &owned_binding)
+ .unwrap_or_else(|| noop_visit(Fold, &owned_binding)),
+ );
+
+ visit_fields.append_all(quote!(;));
+ visit_mut_fields.append_all(quote!(;));
+ fold_fields.append_all(quote!(,));
+ }
+
+ visit_variants.append_all(quote! {
+ #ty::#variant_ident(#bind_visit_fields) => {
+ #visit_fields
+ }
+ });
+
+ visit_mut_variants.append_all(quote! {
+ #ty::#variant_ident(#bind_visit_mut_fields) => {
+ #visit_mut_fields
+ }
+ });
+
+ fold_variants.append_all(quote! {
+ #ty::#variant_ident(#bind_fold_fields) => {
+ #ty::#variant_ident(
+ #fold_fields
+ )
+ }
+ });
+ }
+ }
+
+ visit_impl.append_all(quote! {
+ match *_i {
+ #visit_variants
+ }
+ });
+
+ visit_mut_impl.append_all(quote! {
+ match *_i {
+ #visit_mut_variants
+ }
+ });
+
+ fold_impl.append_all(quote! {
+ match _i {
+ #fold_variants
+ }
+ });
+ }
+ types::TypeDef::Struct(ref v) => {
+ let mut fold_fields = TokenStream::new();
+
+ for field in v.fields() {
+ let id = Ident::new(field.ident(), Span::call_site());
+ let ref_toks = Owned(quote!(_i.#id));
+ let visit_field = visit(field.ty(), v.features(), types, Visit, &ref_toks)
+ .unwrap_or_else(|| noop_visit(Visit, &ref_toks));
+ visit_impl.append_all(quote! {
+ #visit_field;
+ });
+ let visit_mut_field =
+ visit(field.ty(), v.features(), types, VisitMut, &ref_toks)
+ .unwrap_or_else(|| noop_visit(VisitMut, &ref_toks));
+ visit_mut_impl.append_all(quote! {
+ #visit_mut_field;
+ });
+ let fold = visit(field.ty(), v.features(), types, Fold, &ref_toks)
+ .unwrap_or_else(|| noop_visit(Fold, &ref_toks));
+
+ fold_fields.append_all(quote! {
+ #id: #fold,
+ });
+ }
+
+ if !v.fields().is_empty() {
+ fold_impl.append_all(quote! {
+ #ty {
+ #fold_fields
+ }
+ })
+ } else {
+ if ty == "Ident" {
+ fold_impl.append_all(quote! {
+ let mut _i = _i;
+ let span = _visitor.fold_span(_i.span());
+ _i.set_span(span);
+ });
+ }
+ fold_impl.append_all(quote! {
+ _i
+ });
+ }
+ }
+ }
+
+ let mut include_fold_impl = true;
+ if let types::TypeDef::Struct(ref data) = s {
+ if !data.all_fields_pub() {
+ include_fold_impl = false;
+ }
+ }
+
+ state.visit_trait.append_all(quote! {
+ #features
+ fn #visit_fn(&mut self, i: &'ast #ty) {
+ #visit_fn(self, i)
+ }
+ });
+
+ state.visit_impl.append_all(quote! {
+ #features
+ pub fn #visit_fn<'ast, V: Visit<'ast> + ?Sized>(
+ _visitor: &mut V, _i: &'ast #ty
+ ) {
+ #visit_impl
+ }
+ });
+
+ state.visit_mut_trait.append_all(quote! {
+ #features
+ fn #visit_mut_fn(&mut self, i: &mut #ty) {
+ #visit_mut_fn(self, i)
+ }
+ });
+
+ state.visit_mut_impl.append_all(quote! {
+ #features
+ pub fn #visit_mut_fn<V: VisitMut + ?Sized>(
+ _visitor: &mut V, _i: &mut #ty
+ ) {
+ #visit_mut_impl
+ }
+ });
+
+ state.fold_trait.append_all(quote! {
+ #features
+ fn #fold_fn(&mut self, i: #ty) -> #ty {
+ #fold_fn(self, i)
+ }
+ });
+
+ if include_fold_impl {
+ state.fold_impl.append_all(quote! {
+ #features
+ pub fn #fold_fn<V: Fold + ?Sized>(
+ _visitor: &mut V, _i: #ty
+ ) -> #ty {
+ #fold_impl
+ }
+ });
+ }
+ }
+}
+
+fn write_file(path: &str, content: TokenStream) {
+ let mut file = File::create(path).unwrap();
+ write!(
+ file,
+ "// THIS FILE IS AUTOMATICALLY GENERATED; DO NOT EDIT\n\n"
+ )
+ .unwrap();
+ let mut config = rustfmt::Config::default();
+ config.set().emit_mode(rustfmt::EmitMode::Stdout);
+ config.set().verbose(rustfmt::Verbosity::Quiet);
+ config.set().format_macro_matchers(true);
+ config.set().normalize_doc_attributes(true);
+ let mut session = rustfmt::Session::new(config, Some(&mut file));
+ session
+ .format(rustfmt::Input::Text(content.to_string()))
+ .unwrap();
+}
+
+pub fn generate(types: &[types::TypeDef]) {
+ let mut state = codegen::State::default();
+ for s in types {
+ codegen::generate(&mut state, s, types);
+ }
+
+ let full_macro = quote! {
+ #[cfg(feature = "full")]
+ macro_rules! full {
+ ($e:expr) => {
+ $e
+ };
+ }
+
+ #[cfg(all(feature = "derive", not(feature = "full")))]
+ macro_rules! full {
+ ($e:expr) => {
+ unreachable!()
+ };
+ }
+ };
+
+ let skip_macro = quote! {
+ #[cfg(any(feature = "full", feature = "derive"))]
+ macro_rules! skip {
+ ($($tt:tt)*) => {};
+ }
+ };
+
+ let fold_trait = state.fold_trait;
+ let fold_impl = state.fold_impl;
+ write_file(
+ FOLD_SRC,
+ quote! {
+ // Unreachable code is generated sometimes without the full feature.
+ #![allow(unreachable_code)]
+
+ use *;
+ #[cfg(any(feature = "full", feature = "derive"))]
+ use token::{Brace, Bracket, Paren, Group};
+ use proc_macro2::Span;
+ #[cfg(any(feature = "full", feature = "derive"))]
+ use gen::helper::fold::*;
+
+ #full_macro
+
+ /// Syntax tree traversal to transform the nodes of an owned syntax tree.
+ ///
+ /// See the [module documentation] for details.
+ ///
+ /// [module documentation]: index.html
+ ///
+ /// *This trait is available if Syn is built with the `"fold"` feature.*
+ pub trait Fold {
+ #fold_trait
+ }
+
+ #[cfg(any(feature = "full", feature = "derive"))]
+ macro_rules! fold_span_only {
+ ($f:ident : $t:ident) => {
+ pub fn $f<V: Fold + ?Sized>(_visitor: &mut V, mut _i: $t) -> $t {
+ let span = _visitor.fold_span(_i.span());
+ _i.set_span(span);
+ _i
+ }
+ }
+ }
+
+ #[cfg(any(feature = "full", feature = "derive"))]
+ fold_span_only!(fold_lit_byte: LitByte);
+ #[cfg(any(feature = "full", feature = "derive"))]
+ fold_span_only!(fold_lit_byte_str: LitByteStr);
+ #[cfg(any(feature = "full", feature = "derive"))]
+ fold_span_only!(fold_lit_char: LitChar);
+ #[cfg(any(feature = "full", feature = "derive"))]
+ fold_span_only!(fold_lit_float: LitFloat);
+ #[cfg(any(feature = "full", feature = "derive"))]
+ fold_span_only!(fold_lit_int: LitInt);
+ #[cfg(any(feature = "full", feature = "derive"))]
+ fold_span_only!(fold_lit_str: LitStr);
+
+ #fold_impl
+ },
+ );
+
+ let visit_trait = state.visit_trait;
+ let visit_impl = state.visit_impl;
+ write_file(
+ VISIT_SRC,
+ quote! {
+ #![cfg_attr(feature = "cargo-clippy", allow(trivially_copy_pass_by_ref))]
+
+ use *;
+ #[cfg(any(feature = "full", feature = "derive"))]
+ use punctuated::Punctuated;
+ use proc_macro2::Span;
+ #[cfg(any(feature = "full", feature = "derive"))]
+ use gen::helper::visit::*;
+
+ #full_macro
+ #skip_macro
+
+ /// Syntax tree traversal to walk a shared borrow of a syntax tree.
+ ///
+ /// See the [module documentation] for details.
+ ///
+ /// [module documentation]: index.html
+ ///
+ /// *This trait is available if Syn is built with the `"visit"` feature.*
+ pub trait Visit<'ast> {
+ #visit_trait
+ }
+
+ #visit_impl
+ },
+ );
+
+ let visit_mut_trait = state.visit_mut_trait;
+ let visit_mut_impl = state.visit_mut_impl;
+ write_file(
+ VISIT_MUT_SRC,
+ quote! {
+ use *;
+ #[cfg(any(feature = "full", feature = "derive"))]
+ use punctuated::Punctuated;
+ use proc_macro2::Span;
+ #[cfg(any(feature = "full", feature = "derive"))]
+ use gen::helper::visit_mut::*;
+
+ #full_macro
+ #skip_macro
+
+ /// Syntax tree traversal to mutate an exclusive borrow of a syntax tree in
+ /// place.
+ ///
+ /// See the [module documentation] for details.
+ ///
+ /// [module documentation]: index.html
+ ///
+ /// *This trait is available if Syn is built with the `"visit-mut"` feature.*
+ pub trait VisitMut {
+ #visit_mut_trait
+ }
+
+ #visit_mut_impl
+ },
+ );
+}
diff --git a/codegen/src/main.rs b/codegen/src/main.rs
index ed600ac..fa577cb 100644
--- a/codegen/src/main.rs
+++ b/codegen/src/main.rs
@@ -13,1169 +13,19 @@
#![recursion_limit = "128"]
#![allow(clippy::needless_pass_by_value)]
-#[macro_use]
-extern crate failure;
extern crate inflections;
extern crate proc_macro2;
#[macro_use]
extern crate quote;
extern crate rustfmt_nightly as rustfmt;
+#[macro_use]
extern crate syn;
-use failure::{err_msg, Error};
-use proc_macro2::{Span, TokenStream};
-use quote::ToTokens;
-use syn::{Attribute, Data, DataStruct, DeriveInput, Ident, Item};
-
-use std::collections::BTreeMap;
-use std::fmt::{self, Debug};
-use std::fs::File;
-use std::io::{Read, Write};
-use std::path::Path;
-
-const SYN_CRATE_ROOT: &str = "../src/lib.rs";
-
-const FOLD_SRC: &str = "../src/gen/fold.rs";
-const VISIT_SRC: &str = "../src/gen/visit.rs";
-const VISIT_MUT_SRC: &str = "../src/gen/visit_mut.rs";
-
-const IGNORED_MODS: &[&str] = &["fold", "visit", "visit_mut"];
-
-const EXTRA_TYPES: &[&str] = &["Lifetime"];
-
-const TERMINAL_TYPES: &[&str] = &["Span", "Ident"];
-
-fn get_features(attrs: &[Attribute], mut features: TokenStream) -> TokenStream {
- for attr in attrs {
- if attr.path.is_ident("cfg") {
- attr.to_tokens(&mut features);
- }
- }
- features
-}
-
-#[derive(Clone)]
-pub struct AstItem {
- ast: DeriveInput,
- features: TokenStream,
- // True if this is an ast_enum_of_structs! item with a #full annotation.
- eos_full: bool,
-}
-
-impl Debug for AstItem {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.debug_struct("AstItem")
- .field("ast", &self.ast)
- .field("features", &self.features.to_string())
- .finish()
- }
-}
-
-// NOTE: BTreeMap is used here instead of HashMap to have deterministic output.
-type Lookup = BTreeMap<Ident, AstItem>;
-
-fn load_file<P: AsRef<Path>>(
- name: P,
- features: &TokenStream,
- lookup: &mut Lookup,
-) -> Result<(), Error> {
- let name = name.as_ref();
- let parent = name.parent().ok_or_else(|| err_msg("no parent path"))?;
-
- let mut f = File::open(name)?;
- let mut src = String::new();
- f.read_to_string(&mut src)?;
-
- // Parse the file
- let file =
- syn::parse_file(&src).map_err(|_| format_err!("failed to parse {}", name.display()))?;
-
- // Collect all of the interesting AstItems declared in this file or submodules.
- 'items: for item in file.items {
- match item {
- Item::Mod(item) => {
- // Don't inspect inline modules.
- if item.content.is_some() {
- continue;
- }
-
- // We don't want to try to load the generated rust files and
- // parse them, so we ignore them here.
- for name in IGNORED_MODS {
- if item.ident == name {
- continue 'items;
- }
- }
-
- // Lookup any #[cfg()] attributes on the module and add them to
- // the feature set.
- //
- // The derive module is weird because it is built with either
- // `full` or `derive` but exported only under `derive`.
- let features = if item.ident == "derive" {
- quote!(#[cfg(feature = "derive")])
- } else {
- get_features(&item.attrs, features.clone())
- };
-
- // Look up the submodule file, and recursively parse it.
- // XXX: Only handles same-directory .rs file submodules.
- let path = parent.join(&format!("{}.rs", item.ident));
- load_file(path, &features, lookup)?;
- }
- Item::Macro(item) => {
- // Lookip any #[cfg()] attributes directly on the macro
- // invocation, and add them to the feature set.
- let features = get_features(&item.attrs, features.clone());
-
- // Try to parse the AstItem declaration out of the item.
- let tts = &item.mac.tts;
- let found = if item.mac.path.is_ident("ast_struct") {
- syn::parse2::<parsing::AstStruct>(quote!(#tts))
- .map_err(|_| err_msg("failed to parse ast_struct"))?
- .0
- } else if item.mac.path.is_ident("ast_enum") {
- syn::parse2::<parsing::AstEnum>(quote!(#tts))
- .map_err(|_| err_msg("failed to parse ast_enum"))?
- .0
- } else if item.mac.path.is_ident("ast_enum_of_structs") {
- syn::parse2::<parsing::AstEnumOfStructs>(quote!(#tts))
- .map_err(|_| err_msg("failed to parse ast_enum_of_structs"))?
- .0
- } else {
- continue;
- };
-
- // Record our features on the parsed AstItems.
- for mut item in found {
- features.to_tokens(&mut item.features);
- lookup.insert(item.ast.ident.clone(), item);
- }
- }
- Item::Struct(item) => {
- let ident = item.ident;
- if EXTRA_TYPES.contains(&&ident.to_string()[..]) {
- lookup.insert(
- ident.clone(),
- AstItem {
- ast: DeriveInput {
- ident,
- vis: item.vis,
- attrs: item.attrs,
- generics: item.generics,
- data: Data::Struct(DataStruct {
- fields: item.fields,
- struct_token: item.struct_token,
- semi_token: item.semi_token,
- }),
- },
- features: features.clone(),
- eos_full: false,
- },
- );
- }
- }
- _ => {}
- }
- }
- Ok(())
-}
-
-mod parsing {
- use super::AstItem;
-
- use proc_macro2::TokenStream;
- use syn;
- use syn::parse::{Parse, ParseStream, Result};
- use syn::*;
-
- fn peek_tag(input: ParseStream, tag: &str) -> bool {
- let ahead = input.fork();
- ahead.parse::<Token![#]>().is_ok()
- && ahead
- .parse::<Ident>()
- .map(|ident| ident == tag)
- .unwrap_or(false)
- }
-
- // Parses #full - returns #[cfg(feature = "full")] if it is present, and
- // nothing otherwise.
- fn full(input: ParseStream) -> (TokenStream, bool) {
- if peek_tag(input, "full") {
- input.parse::<Token![#]>().unwrap();
- input.parse::<Ident>().unwrap();
- (quote!(#[cfg(feature = "full")]), true)
- } else {
- (quote!(), false)
- }
- }
-
- fn skip_manual_extra_traits(input: ParseStream) {
- if peek_tag(input, "manual_extra_traits") {
- input.parse::<Token![#]>().unwrap();
- input.parse::<Ident>().unwrap();
- }
- }
-
- // Parses a simple AstStruct without the `pub struct` prefix.
- fn ast_struct_inner(input: ParseStream) -> Result<AstItem> {
- let ident: Ident = input.parse()?;
- let (features, eos_full) = full(input);
- skip_manual_extra_traits(input);
- let rest: TokenStream = input.parse()?;
- Ok(AstItem {
- ast: syn::parse2(quote! {
- pub struct #ident #rest
- })?,
- features,
- eos_full,
- })
- }
-
- // ast_struct! parsing
- pub struct AstStruct(pub Vec<AstItem>);
- impl Parse for AstStruct {
- fn parse(input: ParseStream) -> Result<Self> {
- input.call(Attribute::parse_outer)?;
- input.parse::<Token![pub]>()?;
- input.parse::<Token![struct]>()?;
- let res = input.call(ast_struct_inner)?;
- Ok(AstStruct(vec![res]))
- }
- }
-
- fn no_visit(input: ParseStream) -> bool {
- if peek_tag(input, "no_visit") {
- input.parse::<Token![#]>().unwrap();
- input.parse::<Ident>().unwrap();
- true
- } else {
- false
- }
- }
-
- // ast_enum! parsing
- pub struct AstEnum(pub Vec<AstItem>);
- impl Parse for AstEnum {
- fn parse(input: ParseStream) -> Result<Self> {
- input.call(Attribute::parse_outer)?;
- input.parse::<Token![pub]>()?;
- input.parse::<Token![enum]>()?;
- let ident: Ident = input.parse()?;
- let no_visit = no_visit(input);
- let rest: TokenStream = input.parse()?;
- Ok(AstEnum(if no_visit {
- vec![]
- } else {
- vec![AstItem {
- ast: syn::parse2(quote! {
- pub enum #ident #rest
- })?,
- features: quote!(),
- eos_full: false,
- }]
- }))
- }
- }
-
- // A single variant of an ast_enum_of_structs!
- struct EosVariant {
- name: Ident,
- member: Option<Path>,
- inner: Option<AstItem>,
- }
- fn eos_variant(input: ParseStream) -> Result<EosVariant> {
- input.call(Attribute::parse_outer)?;
- input.parse::<Token![pub]>()?;
- let variant: Ident = input.parse()?;
- let (member, inner) = if input.peek(token::Paren) {
- let content;
- parenthesized!(content in input);
- if content.fork().call(ast_struct_inner).is_ok() {
- let item = content.call(ast_struct_inner)?;
- (Some(Path::from(item.ast.ident.clone())), Some(item))
- } else {
- let path: Path = content.parse()?;
- (Some(path), None)
- }
- } else {
- (None, None)
- };
- input.parse::<Token![,]>()?;
- Ok(EosVariant {
- name: variant,
- member,
- inner,
- })
- }
-
- // ast_enum_of_structs! parsing
- pub struct AstEnumOfStructs(pub Vec<AstItem>);
- impl Parse for AstEnumOfStructs {
- fn parse(input: ParseStream) -> Result<Self> {
- input.call(Attribute::parse_outer)?;
- input.parse::<Token![pub]>()?;
- input.parse::<Token![enum]>()?;
- let ident: Ident = input.parse()?;
-
- let content;
- braced!(content in input);
- let mut variants = Vec::new();
- while !content.is_empty() {
- variants.push(content.call(eos_variant)?);
- }
-
- if let Some(ident) = input.parse::<Option<Ident>>()? {
- assert_eq!(ident, "do_not_generate_to_tokens");
- }
-
- let enum_item = {
- let variants = variants.iter().map(|v| {
- let name = v.name.clone();
- match v.member {
- Some(ref member) => quote!(#name(#member)),
- None => quote!(#name),
- }
- });
- parse_quote! {
- pub enum #ident {
- #(#variants),*
- }
- }
- };
- let mut items = vec![AstItem {
- ast: enum_item,
- features: quote!(),
- eos_full: false,
- }];
- items.extend(variants.into_iter().filter_map(|v| v.inner));
- Ok(AstEnumOfStructs(items))
- }
- }
-}
-
-mod codegen {
- use super::{AstItem, Lookup};
- use inflections::Inflect;
- use proc_macro2::{Span, TokenStream};
- use quote::{ToTokens, TokenStreamExt};
- use syn::ext::IdentExt;
- use syn::parse::Parser;
- use syn::punctuated::Punctuated;
- use syn::*;
-
- #[derive(Default)]
- pub struct State {
- pub visit_trait: TokenStream,
- pub visit_impl: TokenStream,
- pub visit_mut_trait: TokenStream,
- pub visit_mut_impl: TokenStream,
- pub fold_trait: TokenStream,
- pub fold_impl: TokenStream,
- }
-
- fn under_name(name: Ident) -> Ident {
- Ident::new(&name.to_string().to_snake_case(), Span::call_site())
- }
-
- enum RelevantType<'a> {
- Box(&'a Type),
- Vec(&'a Type),
- Punctuated(&'a Type),
- Option(&'a Type),
- Tuple(&'a Punctuated<Type, Token![,]>),
- Simple(&'a AstItem),
- TokenPunct(TokenStream),
- TokenKeyword(TokenStream),
- TokenGroup(Ident),
- Pass,
- }
-
- fn classify<'a>(ty: &'a Type, lookup: &'a Lookup) -> RelevantType<'a> {
- match *ty {
- Type::Path(TypePath {
- qself: None,
- ref path,
- }) => {
- let last = path.segments.last().unwrap().into_value();
- match &last.ident.to_string()[..] {
- "Box" => RelevantType::Box(first_arg(&last.arguments)),
- "Vec" => RelevantType::Vec(first_arg(&last.arguments)),
- "Punctuated" => RelevantType::Punctuated(first_arg(&last.arguments)),
- "Option" => RelevantType::Option(first_arg(&last.arguments)),
- "Brace" | "Bracket" | "Paren" | "Group" => {
- RelevantType::TokenGroup(last.ident.clone())
- }
- _ => {
- if let Some(item) = lookup.get(&last.ident) {
- RelevantType::Simple(item)
- } else {
- RelevantType::Pass
- }
- }
- }
- }
- Type::Tuple(TypeTuple { ref elems, .. }) => RelevantType::Tuple(elems),
- Type::Macro(TypeMacro { ref mac })
- if mac.path.segments.last().unwrap().into_value().ident == "Token" =>
- {
- let is_ident = Ident::parse_any.parse2(mac.tts.clone()).is_ok();
- let is_underscore = parse2::<Token![_]>(mac.tts.clone()).is_ok();
- if is_ident && !is_underscore {
- RelevantType::TokenKeyword(mac.into_token_stream())
- } else {
- RelevantType::TokenPunct(mac.into_token_stream())
- }
- }
- _ => RelevantType::Pass,
- }
- }
-
- #[derive(Debug, Eq, PartialEq, Copy, Clone)]
- enum Kind {
- Visit,
- VisitMut,
- Fold,
- }
-
- enum Operand {
- Borrowed(TokenStream),
- Owned(TokenStream),
- }
-
- use self::Kind::*;
- use self::Operand::*;
-
- impl Operand {
- fn tokens(&self) -> &TokenStream {
- match *self {
- Borrowed(ref n) | Owned(ref n) => n,
- }
- }
-
- fn ref_tokens(&self) -> TokenStream {
- match *self {
- Borrowed(ref n) => n.clone(),
- Owned(ref n) => quote!(&#n),
- }
- }
-
- fn ref_mut_tokens(&self) -> TokenStream {
- match *self {
- Borrowed(ref n) => n.clone(),
- Owned(ref n) => quote!(&mut #n),
- }
- }
-
- fn owned_tokens(&self) -> TokenStream {
- match *self {
- Borrowed(ref n) => quote!(*#n),
- Owned(ref n) => n.clone(),
- }
- }
- }
-
- fn first_arg(params: &PathArguments) -> &Type {
- let data = match *params {
- PathArguments::AngleBracketed(ref data) => data,
- _ => panic!("Expected at least 1 type argument here"),
- };
-
- match **data
- .args
- .first()
- .expect("Expected at least 1 type argument here")
- .value()
- {
- GenericArgument::Type(ref ty) => ty,
- _ => panic!("Expected at least 1 type argument here"),
- }
- }
-
- fn simple_visit(item: &AstItem, kind: Kind, name: &Operand) -> TokenStream {
- let ident = under_name(item.ast.ident.clone());
-
- match kind {
- Visit => {
- let method = Ident::new(&format!("visit_{}", ident), Span::call_site());
- let name = name.ref_tokens();
- quote! {
- _visitor.#method(#name)
- }
- }
- VisitMut => {
- let method = Ident::new(&format!("visit_{}_mut", ident), Span::call_site());
- let name = name.ref_mut_tokens();
- quote! {
- _visitor.#method(#name)
- }
- }
- Fold => {
- let method = Ident::new(&format!("fold_{}", ident), Span::call_site());
- let name = name.owned_tokens();
- quote! {
- _visitor.#method(#name)
- }
- }
- }
- }
-
- fn box_visit(elem: &Type, lookup: &Lookup, kind: Kind, name: &Operand) -> Option<TokenStream> {
- let name = name.owned_tokens();
- let res = visit(elem, lookup, kind, &Owned(quote!(*#name)))?;
- Some(match kind {
- Fold => quote! {
- Box::new(#res)
- },
- Visit | VisitMut => res,
- })
- }
-
- fn vec_visit(elem: &Type, lookup: &Lookup, kind: Kind, name: &Operand) -> Option<TokenStream> {
- let operand = match kind {
- Visit | VisitMut => Borrowed(quote!(it)),
- Fold => Owned(quote!(it)),
- };
- let val = visit(elem, lookup, kind, &operand)?;
- Some(match kind {
- Visit => {
- let name = name.ref_tokens();
- quote! {
- for it in #name {
- #val
- }
- }
- }
- VisitMut => {
- let name = name.ref_mut_tokens();
- quote! {
- for it in #name {
- #val
- }
- }
- }
- Fold => {
- let name = name.owned_tokens();
- quote! {
- FoldHelper::lift(#name, |it| { #val })
- }
- }
- })
- }
-
- fn punctuated_visit(
- elem: &Type,
- lookup: &Lookup,
- kind: Kind,
- name: &Operand,
- ) -> Option<TokenStream> {
- let operand = match kind {
- Visit | VisitMut => Borrowed(quote!(it)),
- Fold => Owned(quote!(it)),
- };
- let val = visit(elem, lookup, kind, &operand)?;
- Some(match kind {
- Visit => {
- let name = name.ref_tokens();
- quote! {
- for el in Punctuated::pairs(#name) {
- let it = el.value();
- #val
- }
- }
- }
- VisitMut => {
- let name = name.ref_mut_tokens();
- quote! {
- for mut el in Punctuated::pairs_mut(#name) {
- let it = el.value_mut();
- #val
- }
- }
- }
- Fold => {
- let name = name.owned_tokens();
- quote! {
- FoldHelper::lift(#name, |it| { #val })
- }
- }
- })
- }
-
- fn option_visit(
- elem: &Type,
- lookup: &Lookup,
- kind: Kind,
- name: &Operand,
- ) -> Option<TokenStream> {
- let it = match kind {
- Visit | VisitMut => Borrowed(quote!(it)),
- Fold => Owned(quote!(it)),
- };
- let val = visit(elem, lookup, kind, &it)?;
- let name = name.owned_tokens();
- Some(match kind {
- Visit => quote! {
- if let Some(ref it) = #name {
- #val
- }
- },
- VisitMut => quote! {
- if let Some(ref mut it) = #name {
- #val
- }
- },
- Fold => quote! {
- (#name).map(|it| { #val })
- },
- })
- }
-
- fn tuple_visit(
- elems: &Punctuated<Type, Token![,]>,
- lookup: &Lookup,
- kind: Kind,
- name: &Operand,
- ) -> Option<TokenStream> {
- if elems.is_empty() {
- return None;
- }
-
- let mut code = TokenStream::new();
- for (i, elem) in elems.iter().enumerate() {
- let name = name.tokens();
- let i = Index::from(i);
- let it = Owned(quote!((#name).#i));
- let val = visit(elem, lookup, kind, &it).unwrap_or_else(|| noop_visit(kind, &it));
- code.append_all(val);
- match kind {
- Fold => code.append_all(quote!(,)),
- Visit | VisitMut => code.append_all(quote!(;)),
- }
- }
- Some(match kind {
- Fold => quote! {
- (#code)
- },
- Visit | VisitMut => code,
- })
- }
-
- fn token_punct_visit(ty: TokenStream, kind: Kind, name: &Operand) -> TokenStream {
- let name = name.tokens();
- match kind {
- Fold => quote! {
- #ty(tokens_helper(_visitor, &#name.spans))
- },
- Visit => quote! {
- tokens_helper(_visitor, &#name.spans)
- },
- VisitMut => quote! {
- tokens_helper(_visitor, &mut #name.spans)
- },
- }
- }
-
- fn token_keyword_visit(ty: TokenStream, kind: Kind, name: &Operand) -> TokenStream {
- let name = name.tokens();
- match kind {
- Fold => quote! {
- #ty(tokens_helper(_visitor, &#name.span))
- },
- Visit => quote! {
- tokens_helper(_visitor, &#name.span)
- },
- VisitMut => quote! {
- tokens_helper(_visitor, &mut #name.span)
- },
- }
- }
-
- fn token_group_visit(ty: Ident, kind: Kind, name: &Operand) -> TokenStream {
- let name = name.tokens();
- match kind {
- Fold => quote! {
- #ty(tokens_helper(_visitor, &#name.span))
- },
- Visit => quote! {
- tokens_helper(_visitor, &#name.span)
- },
- VisitMut => quote! {
- tokens_helper(_visitor, &mut #name.span)
- },
- }
- }
-
- fn noop_visit(kind: Kind, name: &Operand) -> TokenStream {
- match kind {
- Fold => name.owned_tokens(),
- Visit | VisitMut => {
- let name = name.tokens();
- quote! {
- skip!(#name)
- }
- }
- }
- }
-
- fn visit(ty: &Type, lookup: &Lookup, kind: Kind, name: &Operand) -> Option<TokenStream> {
- match classify(ty, lookup) {
- RelevantType::Box(elem) => box_visit(elem, lookup, kind, name),
- RelevantType::Vec(elem) => vec_visit(elem, lookup, kind, name),
- RelevantType::Punctuated(elem) => punctuated_visit(elem, lookup, kind, name),
- RelevantType::Option(elem) => option_visit(elem, lookup, kind, name),
- RelevantType::Tuple(elems) => tuple_visit(elems, lookup, kind, name),
- RelevantType::Simple(item) => {
- let mut res = simple_visit(item, kind, name);
- Some(if item.eos_full {
- quote! {
- full!(#res)
- }
- } else {
- res
- })
- }
- RelevantType::TokenPunct(ty) => Some(token_punct_visit(ty, kind, name)),
- RelevantType::TokenKeyword(ty) => Some(token_keyword_visit(ty, kind, name)),
- RelevantType::TokenGroup(ty) => Some(token_group_visit(ty, kind, name)),
- RelevantType::Pass => None,
- }
- }
-
- pub fn generate(state: &mut State, lookup: &Lookup, s: &AstItem) {
- let features = &s.features;
- let under_name = under_name(s.ast.ident.clone());
- let ty = &s.ast.ident;
- let visit_fn = Ident::new(&format!("visit_{}", under_name), Span::call_site());
- let visit_mut_fn = Ident::new(&format!("visit_{}_mut", under_name), Span::call_site());
- let fold_fn = Ident::new(&format!("fold_{}", under_name), Span::call_site());
-
- let mut visit_impl = TokenStream::new();
- let mut visit_mut_impl = TokenStream::new();
- let mut fold_impl = TokenStream::new();
-
- match s.ast.data {
- Data::Enum(ref e) => {
- let mut visit_variants = TokenStream::new();
- let mut visit_mut_variants = TokenStream::new();
- let mut fold_variants = TokenStream::new();
-
- for variant in &e.variants {
- let variant_ident = &variant.ident;
-
- match variant.fields {
- Fields::Named(..) => panic!("Doesn't support enum struct variants"),
- Fields::Unnamed(ref fields) => {
- let mut bind_visit_fields = TokenStream::new();
- let mut bind_visit_mut_fields = TokenStream::new();
- let mut bind_fold_fields = TokenStream::new();
-
- let mut visit_fields = TokenStream::new();
- let mut visit_mut_fields = TokenStream::new();
- let mut fold_fields = TokenStream::new();
-
- for (idx, field) in fields.unnamed.iter().enumerate() {
- let name = format!("_binding_{}", idx);
- let binding = Ident::new(&name, Span::call_site());
-
- bind_visit_fields.append_all(quote! {
- ref #binding,
- });
- bind_visit_mut_fields.append_all(quote! {
- ref mut #binding,
- });
- bind_fold_fields.append_all(quote! {
- #binding,
- });
-
- let borrowed_binding = Borrowed(quote!(#binding));
- let owned_binding = Owned(quote!(#binding));
-
- visit_fields.append_all(
- visit(&field.ty, lookup, Visit, &borrowed_binding)
- .unwrap_or_else(|| noop_visit(Visit, &borrowed_binding)),
- );
- visit_mut_fields.append_all(
- visit(&field.ty, lookup, VisitMut, &borrowed_binding)
- .unwrap_or_else(|| noop_visit(VisitMut, &borrowed_binding)),
- );
- fold_fields.append_all(
- visit(&field.ty, lookup, Fold, &owned_binding)
- .unwrap_or_else(|| noop_visit(Fold, &owned_binding)),
- );
-
- visit_fields.append_all(quote!(;));
- visit_mut_fields.append_all(quote!(;));
- fold_fields.append_all(quote!(,));
- }
-
- visit_variants.append_all(quote! {
- #ty::#variant_ident(#bind_visit_fields) => {
- #visit_fields
- }
- });
-
- visit_mut_variants.append_all(quote! {
- #ty::#variant_ident(#bind_visit_mut_fields) => {
- #visit_mut_fields
- }
- });
-
- fold_variants.append_all(quote! {
- #ty::#variant_ident(#bind_fold_fields) => {
- #ty::#variant_ident(
- #fold_fields
- )
- }
- });
- }
- Fields::Unit => {
- visit_variants.append_all(quote! {
- #ty::#variant_ident => {}
- });
- visit_mut_variants.append_all(quote! {
- #ty::#variant_ident => {}
- });
- fold_variants.append_all(quote! {
- #ty::#variant_ident => {
- #ty::#variant_ident
- }
- });
- }
- }
- }
-
- visit_impl.append_all(quote! {
- match *_i {
- #visit_variants
- }
- });
-
- visit_mut_impl.append_all(quote! {
- match *_i {
- #visit_mut_variants
- }
- });
-
- fold_impl.append_all(quote! {
- match _i {
- #fold_variants
- }
- });
- }
- Data::Struct(ref v) => {
- let mut fold_fields = TokenStream::new();
-
- for (idx, field) in v.fields.iter().enumerate() {
- let id = match field.ident {
- Some(ref ident) => Member::Named(ident.clone()),
- None => Member::Unnamed(Index::from(idx)),
- };
- let ref_toks = Owned(quote!(_i.#id));
- let visit_field = visit(&field.ty, lookup, Visit, &ref_toks)
- .unwrap_or_else(|| noop_visit(Visit, &ref_toks));
- visit_impl.append_all(quote! {
- #visit_field;
- });
- let visit_mut_field = visit(&field.ty, lookup, VisitMut, &ref_toks)
- .unwrap_or_else(|| noop_visit(VisitMut, &ref_toks));
- visit_mut_impl.append_all(quote! {
- #visit_mut_field;
- });
- let fold = visit(&field.ty, lookup, Fold, &ref_toks)
- .unwrap_or_else(|| noop_visit(Fold, &ref_toks));
- if let Some(ref name) = field.ident {
- fold_fields.append_all(quote! {
- #name: #fold,
- });
- } else {
- fold_fields.append_all(quote! {
- #fold,
- });
- }
- }
-
- match v.fields {
- Fields::Named(..) | Fields::Unnamed(..) => fold_impl.append_all(quote! {
- #ty {
- #fold_fields
- }
- }),
- Fields::Unit => {
- if ty == "Ident" {
- fold_impl.append_all(quote! {
- let mut _i = _i;
- let span = _visitor.fold_span(_i.span());
- _i.set_span(span);
- });
- }
- fold_impl.append_all(quote! {
- _i
- });
- }
- };
- }
- Data::Union(..) => panic!("Union not supported"),
- }
-
- let mut include_fold_impl = true;
- if let Data::Struct(ref data) = s.ast.data {
- if let Fields::Named(ref fields) = data.fields {
- if fields
- .named
- .iter()
- .any(|field| field.vis == Visibility::Inherited)
- {
- // Discard the generated impl if there are private fields.
- // These have to be handwritten.
- include_fold_impl = false;
- }
- }
- }
-
- state.visit_trait.append_all(quote! {
- #features
- fn #visit_fn(&mut self, i: &'ast #ty) {
- #visit_fn(self, i)
- }
- });
-
- state.visit_impl.append_all(quote! {
- #features
- pub fn #visit_fn<'ast, V: Visit<'ast> + ?Sized>(
- _visitor: &mut V, _i: &'ast #ty
- ) {
- #visit_impl
- }
- });
-
- state.visit_mut_trait.append_all(quote! {
- #features
- fn #visit_mut_fn(&mut self, i: &mut #ty) {
- #visit_mut_fn(self, i)
- }
- });
-
- state.visit_mut_impl.append_all(quote! {
- #features
- pub fn #visit_mut_fn<V: VisitMut + ?Sized>(
- _visitor: &mut V, _i: &mut #ty
- ) {
- #visit_mut_impl
- }
- });
-
- state.fold_trait.append_all(quote! {
- #features
- fn #fold_fn(&mut self, i: #ty) -> #ty {
- #fold_fn(self, i)
- }
- });
-
- if include_fold_impl {
- state.fold_impl.append_all(quote! {
- #features
- pub fn #fold_fn<V: Fold + ?Sized>(
- _visitor: &mut V, _i: #ty
- ) -> #ty {
- #fold_impl
- }
- });
- }
- }
-}
-
-fn write_file(path: &str, content: TokenStream) {
- let mut file = File::create(path).unwrap();
- write!(
- file,
- "// THIS FILE IS AUTOMATICALLY GENERATED; DO NOT EDIT\n\n"
- )
- .unwrap();
- let mut config = rustfmt::Config::default();
- config.set().emit_mode(rustfmt::EmitMode::Stdout);
- config.set().verbose(rustfmt::Verbosity::Quiet);
- config.set().format_macro_matchers(true);
- config.set().normalize_doc_attributes(true);
- let mut session = rustfmt::Session::new(config, Some(&mut file));
- session
- .format(rustfmt::Input::Text(content.to_string()))
- .unwrap();
-}
+mod gen;
+mod parse;
+mod types;
fn main() {
- let mut lookup = BTreeMap::new();
- load_file(SYN_CRATE_ROOT, "e!(), &mut lookup).unwrap();
-
- // Load in any terminal types
- for &tt in TERMINAL_TYPES {
- use syn::*;
- lookup.insert(
- Ident::new(&tt, Span::call_site()),
- AstItem {
- ast: DeriveInput {
- ident: Ident::new(tt, Span::call_site()),
- vis: Visibility::Public(VisPublic {
- pub_token: <Token![pub]>::default(),
- }),
- attrs: vec![],
- generics: Generics::default(),
- data: Data::Struct(DataStruct {
- fields: Fields::Unit,
- struct_token: <Token![struct]>::default(),
- semi_token: None,
- }),
- },
- features: TokenStream::new(),
- eos_full: false,
- },
- );
- }
-
- let mut state = codegen::State::default();
- for s in lookup.values() {
- codegen::generate(&mut state, &lookup, s);
- }
-
- let full_macro = quote! {
- #[cfg(feature = "full")]
- macro_rules! full {
- ($e:expr) => {
- $e
- };
- }
-
- #[cfg(all(feature = "derive", not(feature = "full")))]
- macro_rules! full {
- ($e:expr) => {
- unreachable!()
- };
- }
- };
-
- let skip_macro = quote! {
- #[cfg(any(feature = "full", feature = "derive"))]
- macro_rules! skip {
- ($($tt:tt)*) => {};
- }
- };
-
- let fold_trait = state.fold_trait;
- let fold_impl = state.fold_impl;
- write_file(
- FOLD_SRC,
- quote! {
- // Unreachable code is generated sometimes without the full feature.
- #![allow(unreachable_code)]
-
- use *;
- #[cfg(any(feature = "full", feature = "derive"))]
- use token::{Brace, Bracket, Paren, Group};
- use proc_macro2::Span;
- #[cfg(any(feature = "full", feature = "derive"))]
- use gen::helper::fold::*;
-
- #full_macro
-
- /// Syntax tree traversal to transform the nodes of an owned syntax tree.
- ///
- /// See the [module documentation] for details.
- ///
- /// [module documentation]: index.html
- ///
- /// *This trait is available if Syn is built with the `"fold"` feature.*
- pub trait Fold {
- #fold_trait
- }
-
- #[cfg(any(feature = "full", feature = "derive"))]
- macro_rules! fold_span_only {
- ($f:ident : $t:ident) => {
- pub fn $f<V: Fold + ?Sized>(_visitor: &mut V, mut _i: $t) -> $t {
- let span = _visitor.fold_span(_i.span());
- _i.set_span(span);
- _i
- }
- }
- }
-
- #[cfg(any(feature = "full", feature = "derive"))]
- fold_span_only!(fold_lit_byte: LitByte);
- #[cfg(any(feature = "full", feature = "derive"))]
- fold_span_only!(fold_lit_byte_str: LitByteStr);
- #[cfg(any(feature = "full", feature = "derive"))]
- fold_span_only!(fold_lit_char: LitChar);
- #[cfg(any(feature = "full", feature = "derive"))]
- fold_span_only!(fold_lit_float: LitFloat);
- #[cfg(any(feature = "full", feature = "derive"))]
- fold_span_only!(fold_lit_int: LitInt);
- #[cfg(any(feature = "full", feature = "derive"))]
- fold_span_only!(fold_lit_str: LitStr);
-
- #fold_impl
- },
- );
-
- let visit_trait = state.visit_trait;
- let visit_impl = state.visit_impl;
- write_file(
- VISIT_SRC,
- quote! {
- #![cfg_attr(feature = "cargo-clippy", allow(trivially_copy_pass_by_ref))]
-
- use *;
- #[cfg(any(feature = "full", feature = "derive"))]
- use punctuated::Punctuated;
- use proc_macro2::Span;
- #[cfg(any(feature = "full", feature = "derive"))]
- use gen::helper::visit::*;
-
- #full_macro
- #skip_macro
-
- /// Syntax tree traversal to walk a shared borrow of a syntax tree.
- ///
- /// See the [module documentation] for details.
- ///
- /// [module documentation]: index.html
- ///
- /// *This trait is available if Syn is built with the `"visit"` feature.*
- pub trait Visit<'ast> {
- #visit_trait
- }
-
- #visit_impl
- },
- );
-
- let visit_mut_trait = state.visit_mut_trait;
- let visit_mut_impl = state.visit_mut_impl;
- write_file(
- VISIT_MUT_SRC,
- quote! {
- use *;
- #[cfg(any(feature = "full", feature = "derive"))]
- use punctuated::Punctuated;
- use proc_macro2::Span;
- #[cfg(any(feature = "full", feature = "derive"))]
- use gen::helper::visit_mut::*;
-
- #full_macro
- #skip_macro
-
- /// Syntax tree traversal to mutate an exclusive borrow of a syntax tree in
- /// place.
- ///
- /// See the [module documentation] for details.
- ///
- /// [module documentation]: index.html
- ///
- /// *This trait is available if Syn is built with the `"visit-mut"` feature.*
- pub trait VisitMut {
- #visit_mut_trait
- }
-
- #visit_mut_impl
- },
- );
+ let types = parse::parse();
+ gen::generate(&types);
}
diff --git a/codegen/src/parse.rs b/codegen/src/parse.rs
new file mode 100644
index 0000000..e7eef19
--- /dev/null
+++ b/codegen/src/parse.rs
@@ -0,0 +1,639 @@
+use crate::types;
+
+use proc_macro2::Span;
+use syn::{Data, DataStruct, DeriveInput, Ident, Item};
+
+use std::collections::BTreeMap;
+use std::fs::File;
+use std::io::Read;
+use std::path::Path;
+
+const SYN_CRATE_ROOT: &str = "../src/lib.rs";
+const TOKEN_SRC: &str = "../src/token.rs";
+const IGNORED_MODS: &[&str] = &["fold", "visit", "visit_mut"];
+const EXTRA_TYPES: &[&str] = &["Lifetime"];
+const TERMINAL_TYPES: &[&str] = &["Span", "Ident"];
+
+// NOTE: BTreeMap is used here instead of HashMap to have deterministic output.
+type ItemLookup = BTreeMap<Ident, AstItem>;
+type TokenLookup = BTreeMap<String, String>;
+
+/// Parse the contents of `src` and return a list of AST types.
+pub fn parse() -> Vec<types::TypeDef> {
+ let mut item_lookup = BTreeMap::new();
+ load_file(SYN_CRATE_ROOT, &[], &mut item_lookup).unwrap();
+
+ let token_lookup = load_token_file(TOKEN_SRC).unwrap();
+
+ // Load in any terminal types
+ for &tt in TERMINAL_TYPES {
+ use syn::*;
+ item_lookup.insert(
+ Ident::new(&tt, Span::call_site()),
+ AstItem {
+ ast: DeriveInput {
+ ident: Ident::new(tt, Span::call_site()),
+ vis: Visibility::Public(VisPublic {
+ pub_token: <Token![pub]>::default(),
+ }),
+ attrs: vec![],
+ generics: Generics::default(),
+ data: Data::Struct(DataStruct {
+ fields: Fields::Unit,
+ struct_token: <Token![struct]>::default(),
+ semi_token: None,
+ }),
+ },
+ features: vec![],
+ },
+ );
+ }
+
+ item_lookup
+ .values()
+ .map(|item| introspect_item(item, &item_lookup, &token_lookup))
+ .collect()
+}
+
+/// Data extracted from syn source
+#[derive(Clone)]
+pub struct AstItem {
+ ast: DeriveInput,
+ features: Vec<syn::Attribute>,
+}
+
+fn introspect_item(item: &AstItem, items: &ItemLookup, tokens: &TokenLookup) -> types::TypeDef {
+ let features = introspect_features(&item.features);
+
+ match &item.ast.data {
+ Data::Enum(ref data) => types::TypeDef::Enum(introspect_enum(
+ &item.ast.ident,
+ features,
+ data,
+ items,
+ tokens,
+ )),
+ Data::Struct(ref data) => types::TypeDef::Struct(introspect_struct(
+ &item.ast.ident,
+ features,
+ data,
+ items,
+ tokens,
+ )),
+ Data::Union(..) => panic!("Union not supported"),
+ }
+}
+
+fn introspect_enum(
+ ident: &Ident,
+ features: types::Features,
+ item: &syn::DataEnum,
+ items: &ItemLookup,
+ tokens: &TokenLookup,
+) -> types::Enum {
+ let variants = item
+ .variants
+ .iter()
+ .map(|variant| {
+ let fields = match &variant.fields {
+ syn::Fields::Unnamed(fields) => fields
+ .unnamed
+ .iter()
+ .map(|field| introspect_type(&field.ty, items, tokens))
+ .collect(),
+ syn::Fields::Unit => vec![],
+ _ => panic!("Enum representation not supported"),
+ };
+
+ types::Variant::new(variant.ident.to_string(), fields)
+ })
+ .collect();
+
+ types::Enum::new(ident.to_string(), features, variants)
+}
+
+fn introspect_struct(
+ ident: &Ident,
+ features: types::Features,
+ item: &syn::DataStruct,
+ items: &ItemLookup,
+ tokens: &TokenLookup,
+) -> types::Struct {
+ let mut all_fields_pub = true;
+ let fields = match &item.fields {
+ syn::Fields::Named(fields) => fields
+ .named
+ .iter()
+ .map(|field| {
+ if !is_pub(&field.vis) {
+ all_fields_pub = false;
+ }
+
+ types::Field::new(
+ field.ident.as_ref().unwrap().to_string(),
+ introspect_type(&field.ty, items, tokens),
+ )
+ })
+ .collect(),
+ syn::Fields::Unit => vec![],
+ _ => panic!("Struct representation not supported"),
+ };
+
+ types::Struct::new(ident.to_string(), features, fields, all_fields_pub)
+}
+
+fn introspect_type(item: &syn::Type, items: &ItemLookup, tokens: &TokenLookup) -> types::Type {
+ match item {
+ syn::Type::Path(syn::TypePath {
+ qself: None,
+ ref path,
+ }) => {
+ let last = path.segments.last().unwrap().into_value();
+
+ match &last.ident.to_string()[..] {
+ "Option" => {
+ let nested = introspect_type(first_arg(&last.arguments), items, tokens);
+ types::Type::Option(Box::new(nested))
+ }
+ "Punctuated" => {
+ let nested = introspect_type(first_arg(&last.arguments), items, tokens);
+ let punct = match introspect_type(last_arg(&last.arguments), items, tokens) {
+ types::Type::Token(s) => s,
+ _ => panic!(),
+ };
+
+ types::Type::Punctuated(Box::new(nested), punct)
+ }
+ "Vec" => {
+ let nested = introspect_type(first_arg(&last.arguments), items, tokens);
+ types::Type::Vec(Box::new(nested))
+ }
+ "Box" => {
+ let nested = introspect_type(first_arg(&last.arguments), items, tokens);
+ types::Type::Box(Box::new(nested))
+ }
+ "Brace" | "Bracket" | "Paren" | "Group" => {
+ types::Type::TokenGroup(last.ident.to_string())
+ }
+ "TokenStream" | "Literal" => types::Type::Ext(last.ident.to_string()),
+ "String" | "u32" | "usize" | "bool" => types::Type::Std(last.ident.to_string()),
+ _ => {
+ if items.get(&last.ident).is_some() {
+ types::Type::Item(last.ident.to_string())
+ } else {
+ unimplemented!("{}", last.ident.to_string());
+ }
+ }
+ }
+ }
+ syn::Type::Tuple(syn::TypeTuple { ref elems, .. }) => {
+ let tys = elems
+ .iter()
+ .map(|ty| introspect_type(&ty, items, tokens))
+ .collect();
+ types::Type::Tuple(tys)
+ }
+ syn::Type::Macro(syn::TypeMacro { ref mac })
+ if mac.path.segments.last().unwrap().into_value().ident == "Token" =>
+ {
+ let content = mac.tts.to_string();
+ let ty = tokens.get(&content).unwrap().to_string();
+
+ types::Type::Token(types::Token::new(content, ty))
+ }
+ _ => panic!("{}", quote!(#item).to_string()),
+ }
+}
+
+fn introspect_features(attrs: &[syn::Attribute]) -> types::Features {
+ let mut ret = types::Features::default();
+
+ for attr in attrs {
+ if !attr.path.is_ident("cfg") {
+ continue;
+ }
+
+ let features: types::Features = syn::parse2(attr.tts.clone()).unwrap();
+ ret.join(&features);
+ }
+
+ ret
+}
+
+fn is_pub(vis: &syn::Visibility) -> bool {
+ match vis {
+ syn::Visibility::Public(_) => true,
+ _ => false,
+ }
+}
+
+fn first_arg(params: &syn::PathArguments) -> &syn::Type {
+ let data = match *params {
+ syn::PathArguments::AngleBracketed(ref data) => data,
+ _ => panic!("Expected at least 1 type argument here"),
+ };
+
+ match **data
+ .args
+ .first()
+ .expect("Expected at least 1 type argument here")
+ .value()
+ {
+ syn::GenericArgument::Type(ref ty) => ty,
+ _ => panic!("Expected at least 1 type argument here"),
+ }
+}
+
+fn last_arg(params: &syn::PathArguments) -> &syn::Type {
+ let data = match *params {
+ syn::PathArguments::AngleBracketed(ref data) => data,
+ _ => panic!("Expected at least 1 type argument here"),
+ };
+
+ match **data
+ .args
+ .last()
+ .expect("Expected at least 1 type argument here")
+ .value()
+ {
+ syn::GenericArgument::Type(ref ty) => ty,
+ _ => panic!("Expected at least 1 type argument here"),
+ }
+}
+
+mod parsing {
+ use super::{AstItem, TokenLookup};
+ use crate::types;
+
+ use proc_macro2::TokenStream;
+ use syn;
+ use syn::parse::{Parse, ParseStream, Result};
+ use syn::*;
+
+ use std::collections::BTreeMap;
+
+ fn peek_tag(input: ParseStream, tag: &str) -> bool {
+ let ahead = input.fork();
+ ahead.parse::<Token![#]>().is_ok()
+ && ahead
+ .parse::<Ident>()
+ .map(|ident| ident == tag)
+ .unwrap_or(false)
+ }
+
+ // Parses #full - returns #[cfg(feature = "full")] if it is present, and
+ // nothing otherwise.
+ fn full(input: ParseStream) -> Vec<syn::Attribute> {
+ if peek_tag(input, "full") {
+ input.parse::<Token![#]>().unwrap();
+ input.parse::<Ident>().unwrap();
+ vec![parse_quote!(#[cfg(feature = "full")])]
+ } else {
+ vec![]
+ }
+ }
+
+ fn skip_manual_extra_traits(input: ParseStream) {
+ if peek_tag(input, "manual_extra_traits") {
+ input.parse::<Token![#]>().unwrap();
+ input.parse::<Ident>().unwrap();
+ }
+ }
+
+ // Parses a simple AstStruct without the `pub struct` prefix.
+ fn ast_struct_inner(input: ParseStream) -> Result<AstItem> {
+ let ident: Ident = input.parse()?;
+ let features = full(input);
+ skip_manual_extra_traits(input);
+ let rest: TokenStream = input.parse()?;
+ Ok(AstItem {
+ ast: syn::parse2(quote! {
+ pub struct #ident #rest
+ })?,
+ features,
+ })
+ }
+
+ // ast_struct! parsing
+ pub struct AstStruct(pub(super) Vec<AstItem>);
+ impl Parse for AstStruct {
+ fn parse(input: ParseStream) -> Result<Self> {
+ input.call(Attribute::parse_outer)?;
+ input.parse::<Token![pub]>()?;
+ input.parse::<Token![struct]>()?;
+ let res = input.call(ast_struct_inner)?;
+ Ok(AstStruct(vec![res]))
+ }
+ }
+
+ fn no_visit(input: ParseStream) -> bool {
+ if peek_tag(input, "no_visit") {
+ input.parse::<Token![#]>().unwrap();
+ input.parse::<Ident>().unwrap();
+ true
+ } else {
+ false
+ }
+ }
+
+ // ast_enum! parsing
+ pub struct AstEnum(pub Vec<AstItem>);
+ impl Parse for AstEnum {
+ fn parse(input: ParseStream) -> Result<Self> {
+ input.call(Attribute::parse_outer)?;
+ input.parse::<Token![pub]>()?;
+ input.parse::<Token![enum]>()?;
+ let ident: Ident = input.parse()?;
+ let no_visit = no_visit(input);
+ let rest: TokenStream = input.parse()?;
+ Ok(AstEnum(if no_visit {
+ vec![]
+ } else {
+ vec![AstItem {
+ ast: syn::parse2(quote! {
+ pub enum #ident #rest
+ })?,
+ features: vec![],
+ }]
+ }))
+ }
+ }
+
+ // A single variant of an ast_enum_of_structs!
+ struct EosVariant {
+ name: Ident,
+ member: Option<Path>,
+ inner: Option<AstItem>,
+ }
+ fn eos_variant(input: ParseStream) -> Result<EosVariant> {
+ input.call(Attribute::parse_outer)?;
+ input.parse::<Token![pub]>()?;
+ let variant: Ident = input.parse()?;
+ let (member, inner) = if input.peek(token::Paren) {
+ let content;
+ parenthesized!(content in input);
+ if content.fork().call(ast_struct_inner).is_ok() {
+ let item = content.call(ast_struct_inner)?;
+ (Some(Path::from(item.ast.ident.clone())), Some(item))
+ } else {
+ let path: Path = content.parse()?;
+ (Some(path), None)
+ }
+ } else {
+ (None, None)
+ };
+ input.parse::<Token![,]>()?;
+ Ok(EosVariant {
+ name: variant,
+ member,
+ inner,
+ })
+ }
+
+ // ast_enum_of_structs! parsing
+ pub struct AstEnumOfStructs(pub Vec<AstItem>);
+ impl Parse for AstEnumOfStructs {
+ fn parse(input: ParseStream) -> Result<Self> {
+ input.call(Attribute::parse_outer)?;
+ input.parse::<Token![pub]>()?;
+ input.parse::<Token![enum]>()?;
+ let ident: Ident = input.parse()?;
+
+ let content;
+ braced!(content in input);
+ let mut variants = Vec::new();
+ while !content.is_empty() {
+ variants.push(content.call(eos_variant)?);
+ }
+
+ if let Some(ident) = input.parse::<Option<Ident>>()? {
+ assert_eq!(ident, "do_not_generate_to_tokens");
+ }
+
+ let enum_item = {
+ let variants = variants.iter().map(|v| {
+ let name = v.name.clone();
+ match v.member {
+ Some(ref member) => quote!(#name(#member)),
+ None => quote!(#name),
+ }
+ });
+ parse_quote! {
+ pub enum #ident {
+ #(#variants),*
+ }
+ }
+ };
+ let mut items = vec![AstItem {
+ ast: enum_item,
+ features: vec![],
+ }];
+ items.extend(variants.into_iter().filter_map(|v| v.inner));
+ Ok(AstEnumOfStructs(items))
+ }
+ }
+
+ pub struct TokenMacro(pub TokenLookup);
+ impl Parse for TokenMacro {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let mut tokens = BTreeMap::new();
+ while !input.is_empty() {
+ let content;
+ parenthesized!(content in input);
+ let token = content.parse::<TokenStream>()?.to_string();
+ input.parse::<Token![=]>()?;
+ input.parse::<Token![>]>()?;
+ let content;
+ braced!(content in input);
+ input.parse::<Token![;]>()?;
+ content.parse::<token::Dollar>()?;
+ let path: Path = content.parse()?;
+ let ty = path.segments.last().unwrap().into_value().ident.to_string();
+ tokens.insert(token, ty.to_string());
+ }
+ Ok(TokenMacro(tokens))
+ }
+ }
+
+ fn parse_feature(input: ParseStream) -> Result<String> {
+ let i: syn::Ident = input.parse()?;
+ assert_eq!(i, "feature");
+
+ input.parse::<Token![=]>()?;
+ let s = input.parse::<syn::LitStr>()?;
+
+ Ok(s.value())
+ }
+
+ impl Parse for types::Features {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let mut features = vec![];
+
+ let level_1;
+ parenthesized!(level_1 in input);
+
+ let i: syn::Ident = level_1.fork().parse()?;
+
+ if i == "any" {
+ level_1.parse::<syn::Ident>()?;
+
+ let level_2;
+ parenthesized!(level_2 in level_1);
+
+ while !level_2.is_empty() {
+ features.push(parse_feature(&level_2)?);
+
+ if !level_2.is_empty() {
+ level_2.parse::<Token![,]>()?;
+ }
+ }
+ } else if i == "feature" {
+ features.push(parse_feature(&level_1)?);
+ assert!(level_1.is_empty());
+ } else {
+ panic!("{:?}", i);
+ }
+
+ assert!(input.is_empty());
+
+ Ok(types::Features::new(features))
+ }
+ }
+}
+
+fn get_features(attrs: &[syn::Attribute], base: &[syn::Attribute]) -> Vec<syn::Attribute> {
+ let mut ret = base.to_owned();
+
+ for attr in attrs {
+ if attr.path.is_ident("cfg") {
+ ret.push(attr.clone());
+ }
+ }
+
+ ret
+}
+
+type Error = Box<::std::error::Error>;
+
+fn load_file<P: AsRef<Path>>(
+ name: P,
+ features: &[syn::Attribute],
+ lookup: &mut ItemLookup,
+) -> Result<(), Error> {
+ let name = name.as_ref();
+ let parent = name.parent().ok_or("no parent path")?;
+
+ let mut f = File::open(name)?;
+ let mut src = String::new();
+ f.read_to_string(&mut src)?;
+
+ // Parse the file
+ let file = syn::parse_file(&src)?;
+
+ // Collect all of the interesting AstItems declared in this file or submodules.
+ 'items: for item in file.items {
+ match item {
+ Item::Mod(item) => {
+ // Don't inspect inline modules.
+ if item.content.is_some() {
+ continue;
+ }
+
+ // We don't want to try to load the generated rust files and
+ // parse them, so we ignore them here.
+ for name in IGNORED_MODS {
+ if item.ident == name {
+ continue 'items;
+ }
+ }
+
+ // Lookup any #[cfg()] attributes on the module and add them to
+ // the feature set.
+ //
+ // The derive module is weird because it is built with either
+ // `full` or `derive` but exported only under `derive`.
+ let features = if item.ident == "derive" {
+ vec![parse_quote!(#[cfg(feature = "derive")])]
+ } else {
+ get_features(&item.attrs, features)
+ };
+
+ // Look up the submodule file, and recursively parse it.
+ // XXX: Only handles same-directory .rs file submodules.
+ let path = parent.join(&format!("{}.rs", item.ident));
+ load_file(path, &features, lookup)?;
+ }
+ Item::Macro(item) => {
+ // Lookip any #[cfg()] attributes directly on the macro
+ // invocation, and add them to the feature set.
+ let features = get_features(&item.attrs, features);
+
+ // Try to parse the AstItem declaration out of the item.
+ let tts = &item.mac.tts;
+ let found = if item.mac.path.is_ident("ast_struct") {
+ syn::parse2::<parsing::AstStruct>(quote!(#tts))?.0
+ } else if item.mac.path.is_ident("ast_enum") {
+ syn::parse2::<parsing::AstEnum>(quote!(#tts))?.0
+ } else if item.mac.path.is_ident("ast_enum_of_structs") {
+ syn::parse2::<parsing::AstEnumOfStructs>(quote!(#tts))?.0
+ } else {
+ continue;
+ };
+
+ // Record our features on the parsed AstItems.
+ for mut item in found {
+ item.features.extend(features.clone());
+ lookup.insert(item.ast.ident.clone(), item);
+ }
+ }
+ Item::Struct(item) => {
+ let ident = item.ident;
+ if EXTRA_TYPES.contains(&&ident.to_string()[..]) {
+ lookup.insert(
+ ident.clone(),
+ AstItem {
+ ast: DeriveInput {
+ ident,
+ vis: item.vis,
+ attrs: item.attrs,
+ generics: item.generics,
+ data: Data::Struct(DataStruct {
+ fields: item.fields,
+ struct_token: item.struct_token,
+ semi_token: item.semi_token,
+ }),
+ },
+ features: features.to_owned(),
+ },
+ );
+ }
+ }
+ _ => {}
+ }
+ }
+ Ok(())
+}
+
+fn load_token_file<P: AsRef<Path>>(name: P) -> Result<TokenLookup, Error> {
+ let name = name.as_ref();
+ let mut f = File::open(name)?;
+ let mut src = String::new();
+ f.read_to_string(&mut src)?;
+ let file = syn::parse_file(&src)?;
+ for item in file.items {
+ match item {
+ Item::Macro(item) => {
+ match item.ident {
+ Some(ref i) if i == "Token" => {}
+ _ => continue,
+ }
+ let tts = &item.mac.tts;
+ let tokens = syn::parse2::<parsing::TokenMacro>(quote!(#tts))?.0;
+ return Ok(tokens);
+ }
+ _ => {}
+ }
+ }
+
+ Err("failed to parse Token macro".into())
+}
diff --git a/codegen/src/types.rs b/codegen/src/types.rs
new file mode 100644
index 0000000..76c3773
--- /dev/null
+++ b/codegen/src/types.rs
@@ -0,0 +1,213 @@
+use std::ops;
+
+#[derive(Debug)]
+pub enum TypeDef {
+ Struct(Struct),
+ Enum(Enum),
+}
+
+#[derive(Debug)]
+pub struct Struct {
+ ident: String,
+ features: Features,
+ fields: Vec<Field>,
+ all_fields_pub: bool,
+}
+
+#[derive(Debug)]
+pub struct Enum {
+ ident: String,
+ features: Features,
+ variants: Vec<Variant>,
+}
+
+#[derive(Debug)]
+pub struct Variant {
+ ident: String,
+ fields: Vec<Type>,
+}
+
+#[derive(Debug)]
+pub struct Field {
+ ident: String,
+ ty: Type,
+}
+
+#[derive(Debug)]
+pub enum Type {
+ /// Type defined by `syn`
+ Item(String),
+
+ /// Type defined in `std`.
+ Std(String),
+
+ /// Type external to `syn`
+ Ext(String),
+
+ /// Token type
+ Token(Token),
+
+ /// Token group
+ TokenGroup(String),
+
+ /// Punctuated list
+ Punctuated(Box<Type>, Token),
+ Option(Box<Type>),
+ Box(Box<Type>),
+ Vec(Box<Type>),
+ Tuple(Vec<Type>),
+}
+
+#[derive(Debug, Clone)]
+pub struct Token {
+ repr: String,
+ ty: String,
+}
+
+#[derive(Debug, Default, Clone)]
+pub struct Features {
+ any: Vec<String>,
+}
+
+impl TypeDef {
+ pub fn ident(&self) -> &str {
+ match self {
+ TypeDef::Struct(i) => &i.ident,
+ TypeDef::Enum(i) => &i.ident,
+ }
+ }
+
+ pub fn features(&self) -> &Features {
+ match self {
+ TypeDef::Struct(i) => &i.features,
+ TypeDef::Enum(i) => &i.features,
+ }
+ }
+}
+
+impl Struct {
+ pub fn new(
+ ident: String,
+ features: Features,
+ fields: Vec<Field>,
+ all_fields_pub: bool,
+ ) -> Struct {
+ Struct {
+ ident,
+ features,
+ fields,
+ all_fields_pub,
+ }
+ }
+
+ pub fn features(&self) -> &Features {
+ &self.features
+ }
+
+ pub fn fields(&self) -> &[Field] {
+ &self.fields
+ }
+
+ pub fn all_fields_pub(&self) -> bool {
+ self.all_fields_pub
+ }
+}
+
+impl Enum {
+ pub fn new(ident: String, features: Features, variants: Vec<Variant>) -> Enum {
+ Enum {
+ ident,
+ features,
+ variants,
+ }
+ }
+
+ pub fn variants(&self) -> &[Variant] {
+ &self.variants
+ }
+}
+
+impl Variant {
+ pub fn new(ident: String, fields: Vec<Type>) -> Variant {
+ Variant { ident, fields }
+ }
+
+ pub fn ident(&self) -> &str {
+ &self.ident
+ }
+
+ pub fn fields(&self) -> &[Type] {
+ &self.fields
+ }
+}
+
+impl Field {
+ pub fn new(ident: String, ty: Type) -> Field {
+ Field { ident, ty }
+ }
+
+ pub fn ident(&self) -> &str {
+ &self.ident
+ }
+
+ pub fn ty(&self) -> &Type {
+ &self.ty
+ }
+}
+
+impl Token {
+ pub fn new(repr: String, ty: String) -> Token {
+ Token { repr, ty }
+ }
+
+ pub fn is_keyword(&self) -> bool {
+ let c = self.repr.chars().next().unwrap();
+ c.is_alphabetic()
+ }
+
+ pub fn repr(&self) -> &str {
+ &self.repr
+ }
+
+ pub fn ty(&self) -> &str {
+ &self.ty
+ }
+}
+
+impl Features {
+ pub fn new(any: Vec<String>) -> Features {
+ Features { any }
+ }
+
+ pub fn join(&mut self, other: &Features) {
+ if self.any.is_empty() {
+ self.any = other.any.clone();
+ } else if self.any.len() < other.any.len() {
+ assert!(self.any.iter().all(|f| other.any.contains(f)));
+ } else {
+ assert!(other.any.iter().all(|f| self.any.contains(f)));
+
+ self.any = other.any.clone();
+ }
+ }
+
+ pub fn len(&self) -> usize {
+ self.any.len()
+ }
+
+ pub fn contains(&self, tag: &str) -> bool {
+ self.iter().any(|s| s == tag)
+ }
+
+ pub fn iter(&self) -> impl Iterator<Item = &str> {
+ self.any.iter().map(|s| &s[..])
+ }
+}
+
+impl ops::Index<usize> for Features {
+ type Output = str;
+
+ fn index(&self, index: usize) -> &str {
+ self.any.index(index)
+ }
+}
diff --git a/src/gen/fold.rs b/src/gen/fold.rs
index 0d240a5..4bc6ba7 100644
--- a/src/gen/fold.rs
+++ b/src/gen/fold.rs
@@ -50,7 +50,6 @@
fn fold_arg_self_ref(&mut self, i: ArgSelfRef) -> ArgSelfRef {
fold_arg_self_ref(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_arm(&mut self, i: Arm) -> Arm {
fold_arm(self, i)
@@ -79,7 +78,6 @@
fn fold_binding(&mut self, i: Binding) -> Binding {
fold_binding(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_block(&mut self, i: Block) -> Block {
fold_block(self, i)
@@ -121,22 +119,18 @@
fold_expr(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_array(&mut self, i: ExprArray) -> ExprArray {
fold_expr_array(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_assign(&mut self, i: ExprAssign) -> ExprAssign {
fold_expr_assign(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_assign_op(&mut self, i: ExprAssignOp) -> ExprAssignOp {
fold_expr_assign_op(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_async(&mut self, i: ExprAsync) -> ExprAsync {
fold_expr_async(self, i)
}
@@ -145,17 +139,14 @@
fold_expr_binary(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_block(&mut self, i: ExprBlock) -> ExprBlock {
fold_expr_block(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_box(&mut self, i: ExprBox) -> ExprBox {
fold_expr_box(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_break(&mut self, i: ExprBreak) -> ExprBreak {
fold_expr_break(self, i)
}
@@ -168,12 +159,10 @@
fold_expr_cast(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_closure(&mut self, i: ExprClosure) -> ExprClosure {
fold_expr_closure(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_continue(&mut self, i: ExprContinue) -> ExprContinue {
fold_expr_continue(self, i)
}
@@ -182,22 +171,18 @@
fold_expr_field(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_for_loop(&mut self, i: ExprForLoop) -> ExprForLoop {
fold_expr_for_loop(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_group(&mut self, i: ExprGroup) -> ExprGroup {
fold_expr_group(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_if(&mut self, i: ExprIf) -> ExprIf {
fold_expr_if(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_in_place(&mut self, i: ExprInPlace) -> ExprInPlace {
fold_expr_in_place(self, i)
}
@@ -206,7 +191,6 @@
fold_expr_index(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_let(&mut self, i: ExprLet) -> ExprLet {
fold_expr_let(self, i)
}
@@ -215,22 +199,18 @@
fold_expr_lit(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_loop(&mut self, i: ExprLoop) -> ExprLoop {
fold_expr_loop(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_macro(&mut self, i: ExprMacro) -> ExprMacro {
fold_expr_macro(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_match(&mut self, i: ExprMatch) -> ExprMatch {
fold_expr_match(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_method_call(&mut self, i: ExprMethodCall) -> ExprMethodCall {
fold_expr_method_call(self, i)
}
@@ -243,47 +223,38 @@
fold_expr_path(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_range(&mut self, i: ExprRange) -> ExprRange {
fold_expr_range(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_reference(&mut self, i: ExprReference) -> ExprReference {
fold_expr_reference(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_repeat(&mut self, i: ExprRepeat) -> ExprRepeat {
fold_expr_repeat(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_return(&mut self, i: ExprReturn) -> ExprReturn {
fold_expr_return(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_struct(&mut self, i: ExprStruct) -> ExprStruct {
fold_expr_struct(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_try(&mut self, i: ExprTry) -> ExprTry {
fold_expr_try(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_try_block(&mut self, i: ExprTryBlock) -> ExprTryBlock {
fold_expr_try_block(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_tuple(&mut self, i: ExprTuple) -> ExprTuple {
fold_expr_tuple(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_type(&mut self, i: ExprType) -> ExprType {
fold_expr_type(self, i)
}
@@ -292,7 +263,6 @@
fold_expr_unary(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_unsafe(&mut self, i: ExprUnsafe) -> ExprUnsafe {
fold_expr_unsafe(self, i)
}
@@ -301,12 +271,10 @@
fold_expr_verbatim(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_while(&mut self, i: ExprWhile) -> ExprWhile {
fold_expr_while(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn fold_expr_yield(&mut self, i: ExprYield) -> ExprYield {
fold_expr_yield(self, i)
}
@@ -314,12 +282,10 @@
fn fold_field(&mut self, i: Field) -> Field {
fold_field(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_field_pat(&mut self, i: FieldPat) -> FieldPat {
fold_field_pat(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_field_value(&mut self, i: FieldValue) -> FieldValue {
fold_field_value(self, i)
@@ -376,7 +342,6 @@
fn fold_generic_argument(&mut self, i: GenericArgument) -> GenericArgument {
fold_generic_argument(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_generic_method_argument(&mut self, i: GenericMethodArgument) -> GenericMethodArgument {
fold_generic_method_argument(self, i)
@@ -500,7 +465,6 @@
fn fold_item_verbatim(&mut self, i: ItemVerbatim) -> ItemVerbatim {
fold_item_verbatim(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_label(&mut self, i: Label) -> Label {
fold_label(self, i)
@@ -548,7 +512,6 @@
fn fold_lit_verbatim(&mut self, i: LitVerbatim) -> LitVerbatim {
fold_lit_verbatim(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_local(&mut self, i: Local) -> Local {
fold_local(self, i)
@@ -581,7 +544,6 @@
fn fold_method_sig(&mut self, i: MethodSig) -> MethodSig {
fold_method_sig(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_method_turbofish(&mut self, i: MethodTurbofish) -> MethodTurbofish {
fold_method_turbofish(self, i)
@@ -597,72 +559,58 @@
) -> ParenthesizedGenericArguments {
fold_parenthesized_generic_arguments(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat(&mut self, i: Pat) -> Pat {
fold_pat(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat_box(&mut self, i: PatBox) -> PatBox {
fold_pat_box(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat_ident(&mut self, i: PatIdent) -> PatIdent {
fold_pat_ident(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat_lit(&mut self, i: PatLit) -> PatLit {
fold_pat_lit(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat_macro(&mut self, i: PatMacro) -> PatMacro {
fold_pat_macro(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat_path(&mut self, i: PatPath) -> PatPath {
fold_pat_path(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat_range(&mut self, i: PatRange) -> PatRange {
fold_pat_range(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat_ref(&mut self, i: PatRef) -> PatRef {
fold_pat_ref(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat_slice(&mut self, i: PatSlice) -> PatSlice {
fold_pat_slice(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat_struct(&mut self, i: PatStruct) -> PatStruct {
fold_pat_struct(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat_tuple(&mut self, i: PatTuple) -> PatTuple {
fold_pat_tuple(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat_tuple_struct(&mut self, i: PatTupleStruct) -> PatTupleStruct {
fold_pat_tuple_struct(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat_verbatim(&mut self, i: PatVerbatim) -> PatVerbatim {
fold_pat_verbatim(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_pat_wild(&mut self, i: PatWild) -> PatWild {
fold_pat_wild(self, i)
@@ -695,7 +643,6 @@
fn fold_qself(&mut self, i: QSelf) -> QSelf {
fold_qself(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_range_limits(&mut self, i: RangeLimits) -> RangeLimits {
fold_range_limits(self, i)
@@ -707,7 +654,6 @@
fn fold_span(&mut self, i: Span) -> Span {
fold_span(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn fold_stmt(&mut self, i: Stmt) -> Stmt {
fold_stmt(self, i)
@@ -939,7 +885,6 @@
self_token: Token),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_arm<V: Fold + ?Sized>(_visitor: &mut V, _i: Arm) -> Arm {
Arm {
@@ -1097,7 +1042,6 @@
ty: _visitor.fold_type(_i.ty),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_block<V: Fold + ?Sized>(_visitor: &mut V, _i: Block) -> Block {
Block {
@@ -1234,7 +1178,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_array<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprArray) -> ExprArray {
ExprArray {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1243,7 +1186,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_assign<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprAssign) -> ExprAssign {
ExprAssign {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1253,7 +1195,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_assign_op<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprAssignOp) -> ExprAssignOp {
ExprAssignOp {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1263,7 +1204,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_async<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprAsync) -> ExprAsync {
ExprAsync {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1282,7 +1222,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_block<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprBlock) -> ExprBlock {
ExprBlock {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1291,7 +1230,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_box<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprBox) -> ExprBox {
ExprBox {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1300,7 +1238,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_break<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprBreak) -> ExprBreak {
ExprBreak {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1328,7 +1265,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_closure<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprClosure) -> ExprClosure {
ExprClosure {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1343,7 +1279,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_continue<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprContinue) -> ExprContinue {
ExprContinue {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1361,7 +1296,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_for_loop<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprForLoop) -> ExprForLoop {
ExprForLoop {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1374,7 +1308,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_group<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprGroup) -> ExprGroup {
ExprGroup {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1383,7 +1316,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_if<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprIf) -> ExprIf {
ExprIf {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1399,7 +1331,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_in_place<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprInPlace) -> ExprInPlace {
ExprInPlace {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1418,7 +1349,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_let<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprLet) -> ExprLet {
ExprLet {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1436,7 +1366,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_loop<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprLoop) -> ExprLoop {
ExprLoop {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1446,7 +1375,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_macro<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprMacro) -> ExprMacro {
ExprMacro {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1454,7 +1382,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_match<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprMatch) -> ExprMatch {
ExprMatch {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1465,7 +1392,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_method_call<V: Fold + ?Sized>(
_visitor: &mut V,
_i: ExprMethodCall,
@@ -1497,7 +1423,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_range<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprRange) -> ExprRange {
ExprRange {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1507,7 +1432,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_reference<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprReference) -> ExprReference {
ExprReference {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1517,7 +1441,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_repeat<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprRepeat) -> ExprRepeat {
ExprRepeat {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1528,7 +1451,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_return<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprReturn) -> ExprReturn {
ExprReturn {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1537,7 +1459,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_struct<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprStruct) -> ExprStruct {
ExprStruct {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1549,7 +1470,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_try<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprTry) -> ExprTry {
ExprTry {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1558,7 +1478,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_try_block<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprTryBlock) -> ExprTryBlock {
ExprTryBlock {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1567,7 +1486,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_tuple<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprTuple) -> ExprTuple {
ExprTuple {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1576,7 +1494,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_type<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprType) -> ExprType {
ExprType {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1594,7 +1511,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_unsafe<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprUnsafe) -> ExprUnsafe {
ExprUnsafe {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1607,7 +1523,6 @@
ExprVerbatim { tts: _i.tts }
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_while<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprWhile) -> ExprWhile {
ExprWhile {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1618,7 +1533,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn fold_expr_yield<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprYield) -> ExprYield {
ExprYield {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
@@ -1636,7 +1550,6 @@
ty: _visitor.fold_type(_i.ty),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_field_pat<V: Fold + ?Sized>(_visitor: &mut V, _i: FieldPat) -> FieldPat {
FieldPat {
@@ -1646,7 +1559,6 @@
pat: Box::new(_visitor.fold_pat(*_i.pat)),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_field_value<V: Fold + ?Sized>(_visitor: &mut V, _i: FieldValue) -> FieldValue {
FieldValue {
@@ -1806,7 +1718,6 @@
}
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_generic_method_argument<V: Fold + ?Sized>(
_visitor: &mut V,
@@ -2228,7 +2139,6 @@
pub fn fold_item_verbatim<V: Fold + ?Sized>(_visitor: &mut V, _i: ItemVerbatim) -> ItemVerbatim {
ItemVerbatim { tts: _i.tts }
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_label<V: Fold + ?Sized>(_visitor: &mut V, _i: Label) -> Label {
Label {
@@ -2275,7 +2185,6 @@
pub fn fold_lit_verbatim<V: Fold + ?Sized>(_visitor: &mut V, _i: LitVerbatim) -> LitVerbatim {
LitVerbatim { token: _i.token }
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_local<V: Fold + ?Sized>(_visitor: &mut V, _i: Local) -> Local {
Local {
@@ -2368,7 +2277,6 @@
decl: _visitor.fold_fn_decl(_i.decl),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_method_turbofish<V: Fold + ?Sized>(
_visitor: &mut V,
@@ -2399,7 +2307,6 @@
output: _visitor.fold_return_type(_i.output),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat<V: Fold + ?Sized>(_visitor: &mut V, _i: Pat) -> Pat {
match _i {
@@ -2420,7 +2327,6 @@
Pat::Verbatim(_binding_0) => Pat::Verbatim(_visitor.fold_pat_verbatim(_binding_0)),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat_box<V: Fold + ?Sized>(_visitor: &mut V, _i: PatBox) -> PatBox {
PatBox {
@@ -2428,7 +2334,6 @@
pat: Box::new(_visitor.fold_pat(*_i.pat)),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat_ident<V: Fold + ?Sized>(_visitor: &mut V, _i: PatIdent) -> PatIdent {
PatIdent {
@@ -2443,21 +2348,18 @@
}),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat_lit<V: Fold + ?Sized>(_visitor: &mut V, _i: PatLit) -> PatLit {
PatLit {
expr: Box::new(_visitor.fold_expr(*_i.expr)),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat_macro<V: Fold + ?Sized>(_visitor: &mut V, _i: PatMacro) -> PatMacro {
PatMacro {
mac: _visitor.fold_macro(_i.mac),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat_path<V: Fold + ?Sized>(_visitor: &mut V, _i: PatPath) -> PatPath {
PatPath {
@@ -2465,7 +2367,6 @@
path: _visitor.fold_path(_i.path),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat_range<V: Fold + ?Sized>(_visitor: &mut V, _i: PatRange) -> PatRange {
PatRange {
@@ -2474,7 +2375,6 @@
hi: Box::new(_visitor.fold_expr(*_i.hi)),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat_ref<V: Fold + ?Sized>(_visitor: &mut V, _i: PatRef) -> PatRef {
PatRef {
@@ -2483,7 +2383,6 @@
pat: Box::new(_visitor.fold_pat(*_i.pat)),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat_slice<V: Fold + ?Sized>(_visitor: &mut V, _i: PatSlice) -> PatSlice {
PatSlice {
@@ -2495,7 +2394,6 @@
back: FoldHelper::lift(_i.back, |it| _visitor.fold_pat(it)),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat_struct<V: Fold + ?Sized>(_visitor: &mut V, _i: PatStruct) -> PatStruct {
PatStruct {
@@ -2505,7 +2403,6 @@
dot2_token: (_i.dot2_token).map(|it| Token)),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat_tuple<V: Fold + ?Sized>(_visitor: &mut V, _i: PatTuple) -> PatTuple {
PatTuple {
@@ -2516,7 +2413,6 @@
back: FoldHelper::lift(_i.back, |it| _visitor.fold_pat(it)),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat_tuple_struct<V: Fold + ?Sized>(
_visitor: &mut V,
@@ -2527,12 +2423,10 @@
pat: _visitor.fold_pat_tuple(_i.pat),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat_verbatim<V: Fold + ?Sized>(_visitor: &mut V, _i: PatVerbatim) -> PatVerbatim {
PatVerbatim { tts: _i.tts }
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_pat_wild<V: Fold + ?Sized>(_visitor: &mut V, _i: PatWild) -> PatWild {
PatWild {
@@ -2604,7 +2498,6 @@
gt_token: Token ! [ > ](tokens_helper(_visitor, &_i.gt_token.spans)),
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_range_limits<V: Fold + ?Sized>(_visitor: &mut V, _i: RangeLimits) -> RangeLimits {
match _i {
@@ -2629,7 +2522,6 @@
pub fn fold_span<V: Fold + ?Sized>(_visitor: &mut V, _i: Span) -> Span {
_i
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn fold_stmt<V: Fold + ?Sized>(_visitor: &mut V, _i: Stmt) -> Stmt {
match _i {
diff --git a/src/gen/visit.rs b/src/gen/visit.rs
index b82e2d8..9af098b 100644
--- a/src/gen/visit.rs
+++ b/src/gen/visit.rs
@@ -51,7 +51,6 @@
fn visit_arg_self_ref(&mut self, i: &'ast ArgSelfRef) {
visit_arg_self_ref(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_arm(&mut self, i: &'ast Arm) {
visit_arm(self, i)
@@ -80,7 +79,6 @@
fn visit_binding(&mut self, i: &'ast Binding) {
visit_binding(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_block(&mut self, i: &'ast Block) {
visit_block(self, i)
@@ -122,22 +120,18 @@
visit_expr(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_array(&mut self, i: &'ast ExprArray) {
visit_expr_array(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_assign(&mut self, i: &'ast ExprAssign) {
visit_expr_assign(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_assign_op(&mut self, i: &'ast ExprAssignOp) {
visit_expr_assign_op(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_async(&mut self, i: &'ast ExprAsync) {
visit_expr_async(self, i)
}
@@ -146,17 +140,14 @@
visit_expr_binary(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_block(&mut self, i: &'ast ExprBlock) {
visit_expr_block(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_box(&mut self, i: &'ast ExprBox) {
visit_expr_box(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_break(&mut self, i: &'ast ExprBreak) {
visit_expr_break(self, i)
}
@@ -169,12 +160,10 @@
visit_expr_cast(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_closure(&mut self, i: &'ast ExprClosure) {
visit_expr_closure(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_continue(&mut self, i: &'ast ExprContinue) {
visit_expr_continue(self, i)
}
@@ -183,22 +172,18 @@
visit_expr_field(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_for_loop(&mut self, i: &'ast ExprForLoop) {
visit_expr_for_loop(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_group(&mut self, i: &'ast ExprGroup) {
visit_expr_group(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_if(&mut self, i: &'ast ExprIf) {
visit_expr_if(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_in_place(&mut self, i: &'ast ExprInPlace) {
visit_expr_in_place(self, i)
}
@@ -207,7 +192,6 @@
visit_expr_index(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_let(&mut self, i: &'ast ExprLet) {
visit_expr_let(self, i)
}
@@ -216,22 +200,18 @@
visit_expr_lit(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_loop(&mut self, i: &'ast ExprLoop) {
visit_expr_loop(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_macro(&mut self, i: &'ast ExprMacro) {
visit_expr_macro(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_match(&mut self, i: &'ast ExprMatch) {
visit_expr_match(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_method_call(&mut self, i: &'ast ExprMethodCall) {
visit_expr_method_call(self, i)
}
@@ -244,47 +224,38 @@
visit_expr_path(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_range(&mut self, i: &'ast ExprRange) {
visit_expr_range(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_reference(&mut self, i: &'ast ExprReference) {
visit_expr_reference(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_repeat(&mut self, i: &'ast ExprRepeat) {
visit_expr_repeat(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_return(&mut self, i: &'ast ExprReturn) {
visit_expr_return(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_struct(&mut self, i: &'ast ExprStruct) {
visit_expr_struct(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_try(&mut self, i: &'ast ExprTry) {
visit_expr_try(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_try_block(&mut self, i: &'ast ExprTryBlock) {
visit_expr_try_block(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_tuple(&mut self, i: &'ast ExprTuple) {
visit_expr_tuple(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_type(&mut self, i: &'ast ExprType) {
visit_expr_type(self, i)
}
@@ -293,7 +264,6 @@
visit_expr_unary(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_unsafe(&mut self, i: &'ast ExprUnsafe) {
visit_expr_unsafe(self, i)
}
@@ -302,12 +272,10 @@
visit_expr_verbatim(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_while(&mut self, i: &'ast ExprWhile) {
visit_expr_while(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_yield(&mut self, i: &'ast ExprYield) {
visit_expr_yield(self, i)
}
@@ -315,12 +283,10 @@
fn visit_field(&mut self, i: &'ast Field) {
visit_field(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_field_pat(&mut self, i: &'ast FieldPat) {
visit_field_pat(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_field_value(&mut self, i: &'ast FieldValue) {
visit_field_value(self, i)
@@ -377,7 +343,6 @@
fn visit_generic_argument(&mut self, i: &'ast GenericArgument) {
visit_generic_argument(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_generic_method_argument(&mut self, i: &'ast GenericMethodArgument) {
visit_generic_method_argument(self, i)
@@ -501,7 +466,6 @@
fn visit_item_verbatim(&mut self, i: &'ast ItemVerbatim) {
visit_item_verbatim(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_label(&mut self, i: &'ast Label) {
visit_label(self, i)
@@ -549,7 +513,6 @@
fn visit_lit_verbatim(&mut self, i: &'ast LitVerbatim) {
visit_lit_verbatim(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_local(&mut self, i: &'ast Local) {
visit_local(self, i)
@@ -582,7 +545,6 @@
fn visit_method_sig(&mut self, i: &'ast MethodSig) {
visit_method_sig(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_method_turbofish(&mut self, i: &'ast MethodTurbofish) {
visit_method_turbofish(self, i)
@@ -595,72 +557,58 @@
fn visit_parenthesized_generic_arguments(&mut self, i: &'ast ParenthesizedGenericArguments) {
visit_parenthesized_generic_arguments(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat(&mut self, i: &'ast Pat) {
visit_pat(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_box(&mut self, i: &'ast PatBox) {
visit_pat_box(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_ident(&mut self, i: &'ast PatIdent) {
visit_pat_ident(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_lit(&mut self, i: &'ast PatLit) {
visit_pat_lit(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_macro(&mut self, i: &'ast PatMacro) {
visit_pat_macro(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_path(&mut self, i: &'ast PatPath) {
visit_pat_path(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_range(&mut self, i: &'ast PatRange) {
visit_pat_range(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_ref(&mut self, i: &'ast PatRef) {
visit_pat_ref(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_slice(&mut self, i: &'ast PatSlice) {
visit_pat_slice(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_struct(&mut self, i: &'ast PatStruct) {
visit_pat_struct(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_tuple(&mut self, i: &'ast PatTuple) {
visit_pat_tuple(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_tuple_struct(&mut self, i: &'ast PatTupleStruct) {
visit_pat_tuple_struct(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_verbatim(&mut self, i: &'ast PatVerbatim) {
visit_pat_verbatim(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_wild(&mut self, i: &'ast PatWild) {
visit_pat_wild(self, i)
@@ -693,7 +641,6 @@
fn visit_qself(&mut self, i: &'ast QSelf) {
visit_qself(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_range_limits(&mut self, i: &'ast RangeLimits) {
visit_range_limits(self, i)
@@ -705,7 +652,6 @@
fn visit_span(&mut self, i: &'ast Span) {
visit_span(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_stmt(&mut self, i: &'ast Stmt) {
visit_stmt(self, i)
@@ -917,7 +863,6 @@
};
tokens_helper(_visitor, &_i.self_token.span);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_arm<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast Arm) {
for it in &_i.attrs {
@@ -1074,7 +1019,6 @@
tokens_helper(_visitor, &_i.eq_token.spans);
_visitor.visit_type(&_i.ty);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_block<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast Block) {
tokens_helper(_visitor, &_i.brace_token.span);
@@ -1292,7 +1236,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_array<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprArray) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1304,7 +1247,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_assign<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprAssign) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1314,7 +1256,6 @@
_visitor.visit_expr(&*_i.right);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_assign_op<'ast, V: Visit<'ast> + ?Sized>(
_visitor: &mut V,
_i: &'ast ExprAssignOp,
@@ -1327,7 +1268,6 @@
_visitor.visit_expr(&*_i.right);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_async<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprAsync) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1348,7 +1288,6 @@
_visitor.visit_expr(&*_i.right);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_block<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprBlock) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1359,7 +1298,6 @@
_visitor.visit_block(&_i.block);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_box<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprBox) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1368,7 +1306,6 @@
_visitor.visit_expr(&*_i.expr);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_break<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprBreak) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1403,7 +1340,6 @@
_visitor.visit_type(&*_i.ty);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_closure<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprClosure) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1427,7 +1363,6 @@
_visitor.visit_expr(&*_i.body);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_continue<'ast, V: Visit<'ast> + ?Sized>(
_visitor: &mut V,
_i: &'ast ExprContinue,
@@ -1450,7 +1385,6 @@
_visitor.visit_member(&_i.member);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_for_loop<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprForLoop) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1465,7 +1399,6 @@
_visitor.visit_block(&_i.body);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_group<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprGroup) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1474,7 +1407,6 @@
_visitor.visit_expr(&*_i.expr);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_if<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprIf) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1488,7 +1420,6 @@
};
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_in_place<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprInPlace) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1507,7 +1438,6 @@
_visitor.visit_expr(&*_i.index);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_let<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprLet) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1528,7 +1458,6 @@
_visitor.visit_lit(&_i.lit);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_loop<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprLoop) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1540,7 +1469,6 @@
_visitor.visit_block(&_i.body);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_macro<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprMacro) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1548,7 +1476,6 @@
_visitor.visit_macro(&_i.mac);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_match<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprMatch) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1561,7 +1488,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_method_call<'ast, V: Visit<'ast> + ?Sized>(
_visitor: &mut V,
_i: &'ast ExprMethodCall,
@@ -1600,7 +1526,6 @@
_visitor.visit_path(&_i.path);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_range<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprRange) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1614,7 +1539,6 @@
};
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_reference<'ast, V: Visit<'ast> + ?Sized>(
_visitor: &mut V,
_i: &'ast ExprReference,
@@ -1629,7 +1553,6 @@
_visitor.visit_expr(&*_i.expr);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_repeat<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprRepeat) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1640,7 +1563,6 @@
_visitor.visit_expr(&*_i.len);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_return<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprReturn) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1651,7 +1573,6 @@
};
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_struct<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprStruct) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1670,7 +1591,6 @@
};
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_try<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprTry) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1679,7 +1599,6 @@
tokens_helper(_visitor, &_i.question_token.spans);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_try_block<'ast, V: Visit<'ast> + ?Sized>(
_visitor: &mut V,
_i: &'ast ExprTryBlock,
@@ -1691,7 +1610,6 @@
_visitor.visit_block(&_i.block);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_tuple<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprTuple) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1703,7 +1621,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_type<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprType) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1721,7 +1638,6 @@
_visitor.visit_expr(&*_i.expr);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_unsafe<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprUnsafe) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1737,7 +1653,6 @@
skip!(_i.tts);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_while<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprWhile) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1750,7 +1665,6 @@
_visitor.visit_block(&_i.body);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_yield<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast ExprYield) {
for it in &_i.attrs {
_visitor.visit_attribute(it)
@@ -1774,7 +1688,6 @@
};
_visitor.visit_type(&_i.ty);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_field_pat<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast FieldPat) {
for it in &_i.attrs {
@@ -1786,7 +1699,6 @@
};
_visitor.visit_pat(&*_i.pat);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_field_value<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast FieldValue) {
for it in &_i.attrs {
@@ -1980,7 +1892,6 @@
}
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_generic_method_argument<'ast, V: Visit<'ast> + ?Sized>(
_visitor: &mut V,
@@ -2507,7 +2418,6 @@
) {
skip!(_i.tts);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_label<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast Label) {
_visitor.visit_lifetime(&_i.name);
@@ -2593,7 +2503,6 @@
pub fn visit_lit_verbatim<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast LitVerbatim) {
skip!(_i.token);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_local<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast Local) {
for it in &_i.attrs {
@@ -2698,7 +2607,6 @@
_visitor.visit_ident(&_i.ident);
_visitor.visit_fn_decl(&_i.decl);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_method_turbofish<'ast, V: Visit<'ast> + ?Sized>(
_visitor: &mut V,
@@ -2735,7 +2643,6 @@
}
_visitor.visit_return_type(&_i.output);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast Pat) {
match *_i {
@@ -2780,13 +2687,11 @@
}
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_box<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatBox) {
tokens_helper(_visitor, &_i.box_token.span);
_visitor.visit_pat(&*_i.pat);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_ident<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatIdent) {
if let Some(ref it) = _i.by_ref {
@@ -2801,17 +2706,14 @@
_visitor.visit_pat(&*(it).1);
};
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_lit<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatLit) {
_visitor.visit_expr(&*_i.expr);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_macro<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatMacro) {
_visitor.visit_macro(&_i.mac);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_path<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatPath) {
if let Some(ref it) = _i.qself {
@@ -2819,14 +2721,12 @@
};
_visitor.visit_path(&_i.path);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_range<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatRange) {
_visitor.visit_expr(&*_i.lo);
_visitor.visit_range_limits(&_i.limits);
_visitor.visit_expr(&*_i.hi);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_ref<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatRef) {
tokens_helper(_visitor, &_i.and_token.spans);
@@ -2835,7 +2735,6 @@
};
_visitor.visit_pat(&*_i.pat);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_slice<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatSlice) {
tokens_helper(_visitor, &_i.bracket_token.span);
@@ -2857,7 +2756,6 @@
_visitor.visit_pat(it)
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_struct<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatStruct) {
_visitor.visit_path(&_i.path);
@@ -2870,7 +2768,6 @@
tokens_helper(_visitor, &it.spans)
};
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_tuple<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatTuple) {
tokens_helper(_visitor, &_i.paren_token.span);
@@ -2889,7 +2786,6 @@
_visitor.visit_pat(it)
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_tuple_struct<'ast, V: Visit<'ast> + ?Sized>(
_visitor: &mut V,
@@ -2898,12 +2794,10 @@
_visitor.visit_path(&_i.path);
_visitor.visit_pat_tuple(&_i.pat);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_verbatim<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatVerbatim) {
skip!(_i.tts);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_wild<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatWild) {
tokens_helper(_visitor, &_i.underscore_token.spans);
@@ -2981,7 +2875,6 @@
};
tokens_helper(_visitor, &_i.gt_token.spans);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_range_limits<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast RangeLimits) {
match *_i {
@@ -3004,7 +2897,6 @@
}
}
pub fn visit_span<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast Span) {}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_stmt<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast Stmt) {
match *_i {
diff --git a/src/gen/visit_mut.rs b/src/gen/visit_mut.rs
index 5124b3c..c709bfc 100644
--- a/src/gen/visit_mut.rs
+++ b/src/gen/visit_mut.rs
@@ -54,7 +54,6 @@
fn visit_arg_self_ref_mut(&mut self, i: &mut ArgSelfRef) {
visit_arg_self_ref_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_arm_mut(&mut self, i: &mut Arm) {
visit_arm_mut(self, i)
@@ -83,7 +82,6 @@
fn visit_binding_mut(&mut self, i: &mut Binding) {
visit_binding_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_block_mut(&mut self, i: &mut Block) {
visit_block_mut(self, i)
@@ -125,22 +123,18 @@
visit_expr_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_array_mut(&mut self, i: &mut ExprArray) {
visit_expr_array_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_assign_mut(&mut self, i: &mut ExprAssign) {
visit_expr_assign_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_assign_op_mut(&mut self, i: &mut ExprAssignOp) {
visit_expr_assign_op_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_async_mut(&mut self, i: &mut ExprAsync) {
visit_expr_async_mut(self, i)
}
@@ -149,17 +143,14 @@
visit_expr_binary_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_block_mut(&mut self, i: &mut ExprBlock) {
visit_expr_block_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_box_mut(&mut self, i: &mut ExprBox) {
visit_expr_box_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_break_mut(&mut self, i: &mut ExprBreak) {
visit_expr_break_mut(self, i)
}
@@ -172,12 +163,10 @@
visit_expr_cast_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_closure_mut(&mut self, i: &mut ExprClosure) {
visit_expr_closure_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_continue_mut(&mut self, i: &mut ExprContinue) {
visit_expr_continue_mut(self, i)
}
@@ -186,22 +175,18 @@
visit_expr_field_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_for_loop_mut(&mut self, i: &mut ExprForLoop) {
visit_expr_for_loop_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_group_mut(&mut self, i: &mut ExprGroup) {
visit_expr_group_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_if_mut(&mut self, i: &mut ExprIf) {
visit_expr_if_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_in_place_mut(&mut self, i: &mut ExprInPlace) {
visit_expr_in_place_mut(self, i)
}
@@ -210,7 +195,6 @@
visit_expr_index_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_let_mut(&mut self, i: &mut ExprLet) {
visit_expr_let_mut(self, i)
}
@@ -219,22 +203,18 @@
visit_expr_lit_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_loop_mut(&mut self, i: &mut ExprLoop) {
visit_expr_loop_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_macro_mut(&mut self, i: &mut ExprMacro) {
visit_expr_macro_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_match_mut(&mut self, i: &mut ExprMatch) {
visit_expr_match_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_method_call_mut(&mut self, i: &mut ExprMethodCall) {
visit_expr_method_call_mut(self, i)
}
@@ -247,47 +227,38 @@
visit_expr_path_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_range_mut(&mut self, i: &mut ExprRange) {
visit_expr_range_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_reference_mut(&mut self, i: &mut ExprReference) {
visit_expr_reference_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_repeat_mut(&mut self, i: &mut ExprRepeat) {
visit_expr_repeat_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_return_mut(&mut self, i: &mut ExprReturn) {
visit_expr_return_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_struct_mut(&mut self, i: &mut ExprStruct) {
visit_expr_struct_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_try_mut(&mut self, i: &mut ExprTry) {
visit_expr_try_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_try_block_mut(&mut self, i: &mut ExprTryBlock) {
visit_expr_try_block_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_tuple_mut(&mut self, i: &mut ExprTuple) {
visit_expr_tuple_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_type_mut(&mut self, i: &mut ExprType) {
visit_expr_type_mut(self, i)
}
@@ -296,7 +267,6 @@
visit_expr_unary_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_unsafe_mut(&mut self, i: &mut ExprUnsafe) {
visit_expr_unsafe_mut(self, i)
}
@@ -305,12 +275,10 @@
visit_expr_verbatim_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_while_mut(&mut self, i: &mut ExprWhile) {
visit_expr_while_mut(self, i)
}
#[cfg(feature = "full")]
- #[cfg(any(feature = "full", feature = "derive"))]
fn visit_expr_yield_mut(&mut self, i: &mut ExprYield) {
visit_expr_yield_mut(self, i)
}
@@ -318,12 +286,10 @@
fn visit_field_mut(&mut self, i: &mut Field) {
visit_field_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_field_pat_mut(&mut self, i: &mut FieldPat) {
visit_field_pat_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_field_value_mut(&mut self, i: &mut FieldValue) {
visit_field_value_mut(self, i)
@@ -380,7 +346,6 @@
fn visit_generic_argument_mut(&mut self, i: &mut GenericArgument) {
visit_generic_argument_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_generic_method_argument_mut(&mut self, i: &mut GenericMethodArgument) {
visit_generic_method_argument_mut(self, i)
@@ -504,7 +469,6 @@
fn visit_item_verbatim_mut(&mut self, i: &mut ItemVerbatim) {
visit_item_verbatim_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_label_mut(&mut self, i: &mut Label) {
visit_label_mut(self, i)
@@ -552,7 +516,6 @@
fn visit_lit_verbatim_mut(&mut self, i: &mut LitVerbatim) {
visit_lit_verbatim_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_local_mut(&mut self, i: &mut Local) {
visit_local_mut(self, i)
@@ -585,7 +548,6 @@
fn visit_method_sig_mut(&mut self, i: &mut MethodSig) {
visit_method_sig_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_method_turbofish_mut(&mut self, i: &mut MethodTurbofish) {
visit_method_turbofish_mut(self, i)
@@ -598,72 +560,58 @@
fn visit_parenthesized_generic_arguments_mut(&mut self, i: &mut ParenthesizedGenericArguments) {
visit_parenthesized_generic_arguments_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_mut(&mut self, i: &mut Pat) {
visit_pat_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_box_mut(&mut self, i: &mut PatBox) {
visit_pat_box_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_ident_mut(&mut self, i: &mut PatIdent) {
visit_pat_ident_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_lit_mut(&mut self, i: &mut PatLit) {
visit_pat_lit_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_macro_mut(&mut self, i: &mut PatMacro) {
visit_pat_macro_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_path_mut(&mut self, i: &mut PatPath) {
visit_pat_path_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_range_mut(&mut self, i: &mut PatRange) {
visit_pat_range_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_ref_mut(&mut self, i: &mut PatRef) {
visit_pat_ref_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_slice_mut(&mut self, i: &mut PatSlice) {
visit_pat_slice_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_struct_mut(&mut self, i: &mut PatStruct) {
visit_pat_struct_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_tuple_mut(&mut self, i: &mut PatTuple) {
visit_pat_tuple_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_tuple_struct_mut(&mut self, i: &mut PatTupleStruct) {
visit_pat_tuple_struct_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_verbatim_mut(&mut self, i: &mut PatVerbatim) {
visit_pat_verbatim_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_pat_wild_mut(&mut self, i: &mut PatWild) {
visit_pat_wild_mut(self, i)
@@ -696,7 +644,6 @@
fn visit_qself_mut(&mut self, i: &mut QSelf) {
visit_qself_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_range_limits_mut(&mut self, i: &mut RangeLimits) {
visit_range_limits_mut(self, i)
@@ -708,7 +655,6 @@
fn visit_span_mut(&mut self, i: &mut Span) {
visit_span_mut(self, i)
}
- #[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
fn visit_stmt_mut(&mut self, i: &mut Stmt) {
visit_stmt_mut(self, i)
@@ -920,7 +866,6 @@
};
tokens_helper(_visitor, &mut _i.self_token.span);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_arm_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut Arm) {
for it in &mut _i.attrs {
@@ -1074,7 +1019,6 @@
tokens_helper(_visitor, &mut _i.eq_token.spans);
_visitor.visit_type_mut(&mut _i.ty);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_block_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut Block) {
tokens_helper(_visitor, &mut _i.brace_token.span);
@@ -1289,7 +1233,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_array_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprArray) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1301,7 +1244,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_assign_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprAssign) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1311,7 +1253,6 @@
_visitor.visit_expr_mut(&mut *_i.right);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_assign_op_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprAssignOp) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1321,7 +1262,6 @@
_visitor.visit_expr_mut(&mut *_i.right);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_async_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprAsync) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1342,7 +1282,6 @@
_visitor.visit_expr_mut(&mut *_i.right);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_block_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprBlock) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1353,7 +1292,6 @@
_visitor.visit_block_mut(&mut _i.block);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_box_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprBox) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1362,7 +1300,6 @@
_visitor.visit_expr_mut(&mut *_i.expr);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_break_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprBreak) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1397,7 +1334,6 @@
_visitor.visit_type_mut(&mut *_i.ty);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_closure_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprClosure) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1421,7 +1357,6 @@
_visitor.visit_expr_mut(&mut *_i.body);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_continue_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprContinue) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1441,7 +1376,6 @@
_visitor.visit_member_mut(&mut _i.member);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_for_loop_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprForLoop) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1456,7 +1390,6 @@
_visitor.visit_block_mut(&mut _i.body);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_group_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprGroup) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1465,7 +1398,6 @@
_visitor.visit_expr_mut(&mut *_i.expr);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_if_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprIf) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1479,7 +1411,6 @@
};
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_in_place_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprInPlace) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1498,7 +1429,6 @@
_visitor.visit_expr_mut(&mut *_i.index);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_let_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprLet) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1519,7 +1449,6 @@
_visitor.visit_lit_mut(&mut _i.lit);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_loop_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprLoop) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1531,7 +1460,6 @@
_visitor.visit_block_mut(&mut _i.body);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_macro_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprMacro) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1539,7 +1467,6 @@
_visitor.visit_macro_mut(&mut _i.mac);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_match_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprMatch) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1552,7 +1479,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_method_call_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprMethodCall) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1588,7 +1514,6 @@
_visitor.visit_path_mut(&mut _i.path);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_range_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprRange) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1602,7 +1527,6 @@
};
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_reference_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprReference) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1614,7 +1538,6 @@
_visitor.visit_expr_mut(&mut *_i.expr);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_repeat_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprRepeat) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1625,7 +1548,6 @@
_visitor.visit_expr_mut(&mut *_i.len);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_return_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprReturn) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1636,7 +1558,6 @@
};
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_struct_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprStruct) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1655,7 +1576,6 @@
};
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_try_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprTry) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1664,7 +1584,6 @@
tokens_helper(_visitor, &mut _i.question_token.spans);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_try_block_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprTryBlock) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1673,7 +1592,6 @@
_visitor.visit_block_mut(&mut _i.block);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_tuple_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprTuple) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1685,7 +1603,6 @@
}
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_type_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprType) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1703,7 +1620,6 @@
_visitor.visit_expr_mut(&mut *_i.expr);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_unsafe_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprUnsafe) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1716,7 +1632,6 @@
skip!(_i.tts);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_while_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprWhile) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1729,7 +1644,6 @@
_visitor.visit_block_mut(&mut _i.body);
}
#[cfg(feature = "full")]
-#[cfg(any(feature = "full", feature = "derive"))]
pub fn visit_expr_yield_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ExprYield) {
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
@@ -1753,7 +1667,6 @@
};
_visitor.visit_type_mut(&mut _i.ty);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_field_pat_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut FieldPat) {
for it in &mut _i.attrs {
@@ -1765,7 +1678,6 @@
};
_visitor.visit_pat_mut(&mut *_i.pat);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_field_value_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut FieldValue) {
for it in &mut _i.attrs {
@@ -1953,7 +1865,6 @@
}
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_generic_method_argument_mut<V: VisitMut + ?Sized>(
_visitor: &mut V,
@@ -2456,7 +2367,6 @@
pub fn visit_item_verbatim_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut ItemVerbatim) {
skip!(_i.tts);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_label_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut Label) {
_visitor.visit_lifetime_mut(&mut _i.name);
@@ -2542,7 +2452,6 @@
pub fn visit_lit_verbatim_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut LitVerbatim) {
skip!(_i.token);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_local_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut Local) {
for it in &mut _i.attrs {
@@ -2641,7 +2550,6 @@
_visitor.visit_ident_mut(&mut _i.ident);
_visitor.visit_fn_decl_mut(&mut _i.decl);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_method_turbofish_mut<V: VisitMut + ?Sized>(
_visitor: &mut V,
@@ -2678,7 +2586,6 @@
}
_visitor.visit_return_type_mut(&mut _i.output);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut Pat) {
match *_i {
@@ -2723,13 +2630,11 @@
}
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_box_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut PatBox) {
tokens_helper(_visitor, &mut _i.box_token.span);
_visitor.visit_pat_mut(&mut *_i.pat);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_ident_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut PatIdent) {
if let Some(ref mut it) = _i.by_ref {
@@ -2744,17 +2649,14 @@
_visitor.visit_pat_mut(&mut *(it).1);
};
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_lit_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut PatLit) {
_visitor.visit_expr_mut(&mut *_i.expr);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_macro_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut PatMacro) {
_visitor.visit_macro_mut(&mut _i.mac);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_path_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut PatPath) {
if let Some(ref mut it) = _i.qself {
@@ -2762,14 +2664,12 @@
};
_visitor.visit_path_mut(&mut _i.path);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_range_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut PatRange) {
_visitor.visit_expr_mut(&mut *_i.lo);
_visitor.visit_range_limits_mut(&mut _i.limits);
_visitor.visit_expr_mut(&mut *_i.hi);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_ref_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut PatRef) {
tokens_helper(_visitor, &mut _i.and_token.spans);
@@ -2778,7 +2678,6 @@
};
_visitor.visit_pat_mut(&mut *_i.pat);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_slice_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut PatSlice) {
tokens_helper(_visitor, &mut _i.bracket_token.span);
@@ -2800,7 +2699,6 @@
_visitor.visit_pat_mut(it)
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_struct_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut PatStruct) {
_visitor.visit_path_mut(&mut _i.path);
@@ -2813,7 +2711,6 @@
tokens_helper(_visitor, &mut it.spans)
};
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_tuple_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut PatTuple) {
tokens_helper(_visitor, &mut _i.paren_token.span);
@@ -2832,18 +2729,15 @@
_visitor.visit_pat_mut(it)
}
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_tuple_struct_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut PatTupleStruct) {
_visitor.visit_path_mut(&mut _i.path);
_visitor.visit_pat_tuple_mut(&mut _i.pat);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_verbatim_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut PatVerbatim) {
skip!(_i.tts);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_pat_wild_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut PatWild) {
tokens_helper(_visitor, &mut _i.underscore_token.spans);
@@ -2915,7 +2809,6 @@
};
tokens_helper(_visitor, &mut _i.gt_token.spans);
}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_range_limits_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut RangeLimits) {
match *_i {
@@ -2938,7 +2831,6 @@
}
}
pub fn visit_span_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut Span) {}
-#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "full")]
pub fn visit_stmt_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut Stmt) {
match *_i {