Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use syn::*;
- trait Folder: Sized {
- // Any additions to this trait should happen in form
- // of a call to a public `noop_*` function that only calls
- // out to the folder again, not other `noop_*` functions.
- //
- // This is a necessary API workaround to the problem of not
- // being able to call out to the super default method
- // in an overridden default method.
- fn fold_ident(&mut self, _ident: &Ident) -> Ident {
- noop_fold_ident(self, _ident)
- }
- fn fold_derive_input(&mut self, derive_input: &DeriveInput) -> DeriveInput {
- noop_fold_derive_input(self, derive_input)
- }
- fn fold_ty(&mut self, ty: &Ty) -> Ty {
- noop_fold_ty(self, ty)
- }
- fn fold_generics(&mut self, generics: &Generics) -> Generics {
- noop_fold_generics(self, generics)
- }
- fn fold_ty_param_bound(&mut self, bound: &TyParamBound) -> TyParamBound {
- noop_fold_ty_param_bound(self, bound)
- }
- fn fold_poly_trait_ref(&mut self,
- trait_ref: &PolyTraitRef,
- modifier: &TraitBoundModifier)
- -> PolyTraitRef {
- noop_fold_poly_trait_ref(self, trait_ref, modifier)
- }
- fn fold_variant_data(&mut self,
- data: &VariantData,
- _ident: &Ident,
- _generics: &Generics) -> VariantData {
- noop_fold_variant_data(self, data)
- }
- fn fold_field(&mut self, field: &Field) -> Field {
- noop_fold_field(self, field)
- }
- fn fold_variant(&mut self, variant: &Variant, generics: &Generics) -> Variant {
- noop_fold_variant(self, variant, generics)
- }
- fn fold_lifetime(&mut self, _lifetime: &Lifetime) -> Lifetime {
- noop_fold_lifetime(self, _lifetime)
- }
- fn fold_lifetime_def(&mut self, lifetime: &LifetimeDef) -> LifetimeDef {
- noop_fold_lifetime_def(self, lifetime)
- }
- fn fold_path(&mut self, path: &Path) -> Path {
- noop_fold_path(self, path)
- }
- fn fold_path_segment(&mut self, path_segment: &PathSegment) -> PathSegment {
- noop_fold_path_segment(self, path_segment)
- }
- fn fold_path_parameters(&mut self, path_parameters: &PathParameters) -> PathParameters {
- noop_fold_path_parameters(self, path_parameters)
- }
- fn fold_assoc_type_binding(&mut self, type_binding: &TypeBinding) -> TypeBinding {
- noop_fold_assoc_type_binding(self, type_binding)
- }
- fn fold_attribute(&mut self, _attr: &Attribute) -> Attribute {
- noop_fold_attribute(self, _attr)
- }
- fn fold_fn_ret_ty(&mut self, ret_ty: &FunctionRetTy) -> FunctionRetTy {
- noop_fold_fn_ret_ty(self, ret_ty)
- }
- fn fold_const_expr(&mut self, expr: &ConstExpr) -> ConstExpr {
- noop_fold_const_expr(self, expr)
- }
- fn fold_lit(&mut self, _lit: &Lit) -> Lit {
- noop_fold_lit(self, _lit)
- }
- fn fold_mac(&mut self, mac: &Mac) -> Mac {
- noop_fold_mac(self, mac)
- }
- #[cfg(feature = "full")]
- fn fold_crate(&mut self, _crate: &Crate) -> Crate {
- noop_fold_crate(self, _crate)
- }
- #[cfg(feature = "full")]
- fn fold_item(&mut self, item: &Item) -> Item {
- noop_fold_item(self, item)
- }
- #[cfg(feature = "full")]
- fn fold_expr(&mut self, expr: &Expr) -> Expr {
- noop_fold_expr(self, expr)
- }
- #[cfg(feature = "full")]
- fn fold_foreign_item(&mut self, foreign_item: &ForeignItem) -> ForeignItem {
- noop_fold_foreign_item(self, foreign_item)
- }
- #[cfg(feature = "full")]
- fn fold_pat(&mut self, pat: &Pat) -> Pat {
- noop_fold_pat(self, pat)
- }
- #[cfg(feature = "full")]
- fn fold_fn_decl(&mut self, fn_decl: &FnDecl) -> FnDecl {
- noop_fold_fn_decl(self, fn_decl)
- }
- #[cfg(feature = "full")]
- fn fold_trait_item(&mut self, trait_item: &TraitItem) -> TraitItem {
- noop_fold_trait_item(self, trait_item)
- }
- #[cfg(feature = "full")]
- fn fold_impl_item(&mut self, impl_item: &ImplItem) -> ImplItem {
- noop_fold_impl_item(self, impl_item)
- }
- #[cfg(feature = "full")]
- fn fold_method_sig(&mut self, method_sig: &MethodSig) -> MethodSig {
- noop_fold_method_sig(self, method_sig)
- }
- #[cfg(feature = "full")]
- fn fold_stmt(&mut self, stmt: &Stmt) -> Stmt {
- noop_fold_stmt(self, stmt)
- }
- #[cfg(feature = "full")]
- fn fold_local(&mut self, local: &Local) -> Local {
- noop_fold_local(self, local)
- }
- #[cfg(feature = "full")]
- fn fold_view_path(&mut self, view_path: &ViewPath) -> ViewPath {
- noop_fold_view_path(self, view_path)
- }
- }
- // -
- pub fn noop_fold_ident<F: Folder>(folder: &mut F, _ident: &Ident) -> Ident {
- _ident
- }
- // -
- pub fn noop_fold_derive_input<F: Folder>(folder: &mut F, derive_input: &DeriveInput) -> DeriveInput {
- DeriveInput {
- ident: folder.fold_ident(derive_input.ident),
- vis: derive_input.vis,
- attrs: derive_input.attrs.iter().map(|a| folder.fold_attribute(a)).collect(),
- generics: folder.fold_generics(derive_input.generics),
- body: match derive_input.body {
- Body::Enum(variants) => {
- Body::Enum(folder.fold_variants(variants, derive_input.generics))
- }
- Body::Struct(variant_data) => {
- Body::Struct(folder.fold_variant_data(variant_data, derive_input.ident, derive_input.genericse))
- }
- },
- }
- }
- pub fn noop_fold_ty<F: Folder>(folder: &mut F, ty: &Ty) -> Ty {
- match *ty {
- Ty::Slice(ref inner) => Ty::Slice(folder.fold_ty(inner)),
- Ty::Paren(ref inner) => Ty::Paren(folder.fold_ty(inner)),
- Ty::Ptr(ref mutable_type) => Ty::Ptr(folder.fold_ty(&mutable_type.ty)),
- Ty::Rptr(ref opt_lifetime, ref mutable_type) => {
- Ty::Rptr(opt_lifetime.map(|x| folder.fold_ty(x)), folder.fold_ty(mutable_type.ty))
- }
- Ty::Never => Ty::Never,
- Ty::Infer => Ty::Infer,
- Ty::Tup(ref tuple_element_types) => {
- Ty::Tup(tuple_element_types.map(|x| folder.fold_ty(x)).collect())
- }
- Ty::BareFn(ref bare_fn) => {
- Ty::BareFn(BareFnTy{
- unsafety: bare_fn.unsafety,
- abi: bare_fn.abi,
- lifetimes: bare_fn.lifetimes.iter().map(|l| folder.fold_lifetime_def(l)).collect(),
- inputs: bare_fn.inputs.iter().map(|v| BareFnArg {
- name: v.name.map(|n| folder.fold_ident(n)),
- ty: folder.fold_ty(v.ty)
- } ).collect(),
- output: folder.fold_fn_ret_ty(bare_fn.output),
- variadic: bare_fn.variadic
- })
- }
- Ty::Path(ref maybe_qself, ref path) => {
- Ty::Path(maybe_qself.map(|v| folder.fold_ty(v.ty)), folder.fold_path(path)
- )
- }
- Ty::Array(ref inner, ref len) => {
- Ty::Array(folder.fold_ty(inner), folder.fold_const_expr(len))
- }
- Ty::TraitObject(ref bounds) => Ty::TraitObject(bounds.iter().map(|v| folder.fold_ty_param_bound(v)).collect()),
- Ty::ImplTrait(ref bounds) => Ty::ImplTrait(bounds.iter().map(|v| folder.fold_ty_param_bound(v)).collect()),
- Ty::Mac(ref mac) => {
- Ty::Mac(folder.fold_mac(mac));
- }
- }
- }
- pub fn noop_fold_generics<F: Folder>(folder: &mut F, generics: &Generics) -> Generics {
- panic!();
- }
- pub fn noop_fold_ty_param_bound<F: Folder>(folder: &mut F, bound: &TyParamBound) -> TyParamBound {
- panic!();
- }
- pub fn noop_fold_poly_trait_ref<F: Folder>(folder: &mut F,
- trait_ref: &PolyTraitRef,
- modifier: &TraitBoundModifier)
- -> PolyTraitRef {
- panic!();
- }
- pub fn noop_fold_variant_data<F: Folder>(folder: &mut F,
- data: &VariantData,
- _ident: &Ident,
- _generics: &Generics)
- -> (VariantData, Ident, Generics) {
- panic!();
- }
- pub fn noop_fold_field<F: Folder>(folder: &mut F, field: &Field) -> Field {
- panic!();
- }
- pub fn noop_fold_variant<F: Folder>(folder: &mut F,
- variant: &Variant,
- generics: &Generics)
- -> (Variant, Generics) {
- panic!();
- }
- // -
- pub fn noop_fold_lifetime<F: Folder>(folder: &mut F, _lifetime: &Lifetime) -> Lifetime {
- Lifetime { ident: folder.fold_ident(_lifetime.ident) }
- }
- // -
- pub fn noop_fold_lifetime_def<F: Folder>(folder: &mut F, lifetime: &LifetimeDef) -> LifetimeDef {
- let attrs: Vec<_> = lifetime.attrs.into();
- LifetimeDef {
- attrs: attrs.into_iter()
- .flat_map(|x| folder.fold_attribute(x).into_iter())
- .collect::<Vec<_>>()
- .into(),
- lifetime: folder.fold_lifetime(lifetime.lifetime),
- bounds: lifetime.bounds.iter().map(|l| folder.fold_lifetime(l)).collect(),
- }
- }
- pub fn noop_fold_path<F: Folder>(folder: &mut F, path: &Path) -> Path {
- panic!();
- }
- pub fn noop_fold_path_segment<F: Folder>(folder: &mut F,
- path_segment: &PathSegment)
- -> PathSegment {
- panic!();
- }
- pub fn noop_fold_path_parameters<F: Folder>(folder: &mut F,
- path_parameters: &PathParameters)
- -> PathParameters {
- panic!();
- }
- pub fn noop_fold_assoc_type_binding<F: Folder>(folder: &mut F,
- type_binding: &TypeBinding)
- -> TypeBinding {
- panic!();
- }
- pub fn noop_fold_attribute<F: Folder>(_: &mut F, _attr: &Attribute) -> Attribute {
- _attr
- }
- pub fn noop_fold_fn_ret_ty<F: Folder>(folder: &mut F, ret_ty: &FunctionRetTy) -> FunctionRetTy {
- panic!();
- }
- pub fn noop_fold_const_expr<F: Folder>(folder: &mut F, expr: &ConstExpr) -> ConstExpr {
- panic!();
- }
- pub fn noop_fold_lit<F: Folder>(folder: &mut F, _lit: &Lit) -> Lit {
- panic!();
- }
- pub fn noop_fold_mac<F: Folder>(folder: &mut F, mac: &Mac) -> Mac {
- panic!();
- }
- #[cfg(feature = "full")]
- pub fn noop_fold_crate<F: Folder>(folder: &mut F, _crate: &Crate) -> Crate {
- panic!();
- }
- #[cfg(feature = "full")]
- pub fn noop_fold_item<F: Folder>(folder: &mut F, item: &Item) -> Item {
- panic!();
- }
- #[cfg(feature = "full")]
- pub fn noop_fold_expr<F: Folder>(folder: &mut F, expr: &Expr) -> Expr {
- panic!();
- }
- #[cfg(feature = "full")]
- pub fn noop_fold_foreign_item<F: Folder>(folder: &mut F,
- foreign_item: &ForeignItem)
- -> ForeignItem {
- panic!();
- }
- #[cfg(feature = "full")]
- pub fn noop_fold_pat<F: Folder>(folder: &mut F, pat: &Pat) -> Pat {
- panic!();
- }
- #[cfg(feature = "full")]
- pub fn noop_fold_fn_decl<F: Folder>(folder: &mut F, fn_decl: &FnDecl) -> FnDecl {
- panic!();
- }
- #[cfg(feature = "full")]
- pub fn noop_fold_trait_item<F: Folder>(folder: &mut F, trait_item: &TraitItem) -> TraitItem {
- panic!();
- }
- #[cfg(feature = "full")]
- pub fn noop_fold_impl_item<F: Folder>(folder: &mut F, impl_item: &ImplItem) -> ImplItem {
- panic!();
- }
- #[cfg(feature = "full")]
- pub fn noop_fold_method_sig<F: Folder>(folder: &mut F, method_sig: &MethodSig) -> MethodSig {
- panic!();
- }
- #[cfg(feature = "full")]
- pub fn noop_fold_stmt<F: Folder>(folder: &mut F, stmt: &Stmt) -> Stmt {
- panic!();
- }
- #[cfg(feature = "full")]
- pub fn noop_fold_local<F: Folder>(folder: &mut F, local: &Local) -> Local {
- panic!();
- }
- #[cfg(feature = "full")]
- pub fn noop_fold_view_path<F: Folder>(folder: &mut F, view_path: &ViewPath) -> ViewPath {
- panic!();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement