Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.63 KB | None | 0 0
  1. use syn::*;
  2.  
  3. trait Folder: Sized {
  4. // Any additions to this trait should happen in form
  5. // of a call to a public `noop_*` function that only calls
  6. // out to the folder again, not other `noop_*` functions.
  7. //
  8. // This is a necessary API workaround to the problem of not
  9. // being able to call out to the super default method
  10. // in an overridden default method.
  11.  
  12. fn fold_ident(&mut self, _ident: &Ident) -> Ident {
  13. noop_fold_ident(self, _ident)
  14. }
  15. fn fold_derive_input(&mut self, derive_input: &DeriveInput) -> DeriveInput {
  16. noop_fold_derive_input(self, derive_input)
  17. }
  18. fn fold_ty(&mut self, ty: &Ty) -> Ty {
  19. noop_fold_ty(self, ty)
  20. }
  21. fn fold_generics(&mut self, generics: &Generics) -> Generics {
  22. noop_fold_generics(self, generics)
  23. }
  24. fn fold_ty_param_bound(&mut self, bound: &TyParamBound) -> TyParamBound {
  25. noop_fold_ty_param_bound(self, bound)
  26. }
  27. fn fold_poly_trait_ref(&mut self,
  28. trait_ref: &PolyTraitRef,
  29. modifier: &TraitBoundModifier)
  30. -> PolyTraitRef {
  31. noop_fold_poly_trait_ref(self, trait_ref, modifier)
  32. }
  33. fn fold_variant_data(&mut self,
  34. data: &VariantData,
  35. _ident: &Ident,
  36. _generics: &Generics) -> VariantData {
  37. noop_fold_variant_data(self, data)
  38. }
  39. fn fold_field(&mut self, field: &Field) -> Field {
  40. noop_fold_field(self, field)
  41. }
  42. fn fold_variant(&mut self, variant: &Variant, generics: &Generics) -> Variant {
  43. noop_fold_variant(self, variant, generics)
  44. }
  45. fn fold_lifetime(&mut self, _lifetime: &Lifetime) -> Lifetime {
  46. noop_fold_lifetime(self, _lifetime)
  47. }
  48. fn fold_lifetime_def(&mut self, lifetime: &LifetimeDef) -> LifetimeDef {
  49. noop_fold_lifetime_def(self, lifetime)
  50. }
  51. fn fold_path(&mut self, path: &Path) -> Path {
  52. noop_fold_path(self, path)
  53. }
  54. fn fold_path_segment(&mut self, path_segment: &PathSegment) -> PathSegment {
  55. noop_fold_path_segment(self, path_segment)
  56. }
  57. fn fold_path_parameters(&mut self, path_parameters: &PathParameters) -> PathParameters {
  58. noop_fold_path_parameters(self, path_parameters)
  59. }
  60. fn fold_assoc_type_binding(&mut self, type_binding: &TypeBinding) -> TypeBinding {
  61. noop_fold_assoc_type_binding(self, type_binding)
  62. }
  63. fn fold_attribute(&mut self, _attr: &Attribute) -> Attribute {
  64. noop_fold_attribute(self, _attr)
  65. }
  66. fn fold_fn_ret_ty(&mut self, ret_ty: &FunctionRetTy) -> FunctionRetTy {
  67. noop_fold_fn_ret_ty(self, ret_ty)
  68. }
  69. fn fold_const_expr(&mut self, expr: &ConstExpr) -> ConstExpr {
  70. noop_fold_const_expr(self, expr)
  71. }
  72. fn fold_lit(&mut self, _lit: &Lit) -> Lit {
  73. noop_fold_lit(self, _lit)
  74. }
  75.  
  76. fn fold_mac(&mut self, mac: &Mac) -> Mac {
  77. noop_fold_mac(self, mac)
  78. }
  79.  
  80. #[cfg(feature = "full")]
  81. fn fold_crate(&mut self, _crate: &Crate) -> Crate {
  82. noop_fold_crate(self, _crate)
  83. }
  84. #[cfg(feature = "full")]
  85. fn fold_item(&mut self, item: &Item) -> Item {
  86. noop_fold_item(self, item)
  87. }
  88. #[cfg(feature = "full")]
  89. fn fold_expr(&mut self, expr: &Expr) -> Expr {
  90. noop_fold_expr(self, expr)
  91. }
  92. #[cfg(feature = "full")]
  93. fn fold_foreign_item(&mut self, foreign_item: &ForeignItem) -> ForeignItem {
  94. noop_fold_foreign_item(self, foreign_item)
  95. }
  96. #[cfg(feature = "full")]
  97. fn fold_pat(&mut self, pat: &Pat) -> Pat {
  98. noop_fold_pat(self, pat)
  99. }
  100. #[cfg(feature = "full")]
  101. fn fold_fn_decl(&mut self, fn_decl: &FnDecl) -> FnDecl {
  102. noop_fold_fn_decl(self, fn_decl)
  103. }
  104. #[cfg(feature = "full")]
  105. fn fold_trait_item(&mut self, trait_item: &TraitItem) -> TraitItem {
  106. noop_fold_trait_item(self, trait_item)
  107. }
  108. #[cfg(feature = "full")]
  109. fn fold_impl_item(&mut self, impl_item: &ImplItem) -> ImplItem {
  110. noop_fold_impl_item(self, impl_item)
  111. }
  112. #[cfg(feature = "full")]
  113. fn fold_method_sig(&mut self, method_sig: &MethodSig) -> MethodSig {
  114. noop_fold_method_sig(self, method_sig)
  115. }
  116. #[cfg(feature = "full")]
  117. fn fold_stmt(&mut self, stmt: &Stmt) -> Stmt {
  118. noop_fold_stmt(self, stmt)
  119. }
  120. #[cfg(feature = "full")]
  121. fn fold_local(&mut self, local: &Local) -> Local {
  122. noop_fold_local(self, local)
  123. }
  124. #[cfg(feature = "full")]
  125. fn fold_view_path(&mut self, view_path: &ViewPath) -> ViewPath {
  126. noop_fold_view_path(self, view_path)
  127. }
  128. }
  129.  
  130.  
  131. // -
  132. pub fn noop_fold_ident<F: Folder>(folder: &mut F, _ident: &Ident) -> Ident {
  133. _ident
  134. }
  135.  
  136. // -
  137. pub fn noop_fold_derive_input<F: Folder>(folder: &mut F, derive_input: &DeriveInput) -> DeriveInput {
  138. DeriveInput {
  139. ident: folder.fold_ident(derive_input.ident),
  140. vis: derive_input.vis,
  141. attrs: derive_input.attrs.iter().map(|a| folder.fold_attribute(a)).collect(),
  142. generics: folder.fold_generics(derive_input.generics),
  143. body: match derive_input.body {
  144. Body::Enum(variants) => {
  145. Body::Enum(folder.fold_variants(variants, derive_input.generics))
  146. }
  147. Body::Struct(variant_data) => {
  148. Body::Struct(folder.fold_variant_data(variant_data, derive_input.ident, derive_input.genericse))
  149. }
  150. },
  151. }
  152. }
  153.  
  154. pub fn noop_fold_ty<F: Folder>(folder: &mut F, ty: &Ty) -> Ty {
  155. match *ty {
  156. Ty::Slice(ref inner) => Ty::Slice(folder.fold_ty(inner)),
  157. Ty::Paren(ref inner) => Ty::Paren(folder.fold_ty(inner)),
  158. Ty::Ptr(ref mutable_type) => Ty::Ptr(folder.fold_ty(&mutable_type.ty)),
  159. Ty::Rptr(ref opt_lifetime, ref mutable_type) => {
  160. Ty::Rptr(opt_lifetime.map(|x| folder.fold_ty(x)), folder.fold_ty(mutable_type.ty))
  161. }
  162. Ty::Never => Ty::Never,
  163. Ty::Infer => Ty::Infer,
  164. Ty::Tup(ref tuple_element_types) => {
  165. Ty::Tup(tuple_element_types.map(|x| folder.fold_ty(x)).collect())
  166. }
  167. Ty::BareFn(ref bare_fn) => {
  168. Ty::BareFn(BareFnTy{
  169. unsafety: bare_fn.unsafety,
  170. abi: bare_fn.abi,
  171. lifetimes: bare_fn.lifetimes.iter().map(|l| folder.fold_lifetime_def(l)).collect(),
  172. inputs: bare_fn.inputs.iter().map(|v| BareFnArg {
  173. name: v.name.map(|n| folder.fold_ident(n)),
  174. ty: folder.fold_ty(v.ty)
  175. } ).collect(),
  176. output: folder.fold_fn_ret_ty(bare_fn.output),
  177. variadic: bare_fn.variadic
  178. })
  179. }
  180. Ty::Path(ref maybe_qself, ref path) => {
  181. Ty::Path(maybe_qself.map(|v| folder.fold_ty(v.ty)), folder.fold_path(path)
  182. )
  183. }
  184. Ty::Array(ref inner, ref len) => {
  185. Ty::Array(folder.fold_ty(inner), folder.fold_const_expr(len))
  186. }
  187. Ty::TraitObject(ref bounds) => Ty::TraitObject(bounds.iter().map(|v| folder.fold_ty_param_bound(v)).collect()),
  188. Ty::ImplTrait(ref bounds) => Ty::ImplTrait(bounds.iter().map(|v| folder.fold_ty_param_bound(v)).collect()),
  189. Ty::Mac(ref mac) => {
  190. Ty::Mac(folder.fold_mac(mac));
  191. }
  192. }
  193. }
  194.  
  195. pub fn noop_fold_generics<F: Folder>(folder: &mut F, generics: &Generics) -> Generics {
  196. panic!();
  197.  
  198. }
  199. pub fn noop_fold_ty_param_bound<F: Folder>(folder: &mut F, bound: &TyParamBound) -> TyParamBound {
  200. panic!();
  201.  
  202. }
  203. pub fn noop_fold_poly_trait_ref<F: Folder>(folder: &mut F,
  204. trait_ref: &PolyTraitRef,
  205. modifier: &TraitBoundModifier)
  206. -> PolyTraitRef {
  207. panic!();
  208.  
  209. }
  210. pub fn noop_fold_variant_data<F: Folder>(folder: &mut F,
  211. data: &VariantData,
  212. _ident: &Ident,
  213. _generics: &Generics)
  214. -> (VariantData, Ident, Generics) {
  215. panic!();
  216.  
  217. }
  218. pub fn noop_fold_field<F: Folder>(folder: &mut F, field: &Field) -> Field {
  219. panic!();
  220.  
  221. }
  222. pub fn noop_fold_variant<F: Folder>(folder: &mut F,
  223. variant: &Variant,
  224. generics: &Generics)
  225. -> (Variant, Generics) {
  226. panic!();
  227.  
  228. }
  229.  
  230. // -
  231. pub fn noop_fold_lifetime<F: Folder>(folder: &mut F, _lifetime: &Lifetime) -> Lifetime {
  232. Lifetime { ident: folder.fold_ident(_lifetime.ident) }
  233. }
  234.  
  235. // -
  236. pub fn noop_fold_lifetime_def<F: Folder>(folder: &mut F, lifetime: &LifetimeDef) -> LifetimeDef {
  237. let attrs: Vec<_> = lifetime.attrs.into();
  238. LifetimeDef {
  239. attrs: attrs.into_iter()
  240. .flat_map(|x| folder.fold_attribute(x).into_iter())
  241. .collect::<Vec<_>>()
  242. .into(),
  243. lifetime: folder.fold_lifetime(lifetime.lifetime),
  244. bounds: lifetime.bounds.iter().map(|l| folder.fold_lifetime(l)).collect(),
  245. }
  246. }
  247.  
  248. pub fn noop_fold_path<F: Folder>(folder: &mut F, path: &Path) -> Path {
  249. panic!();
  250.  
  251. }
  252. pub fn noop_fold_path_segment<F: Folder>(folder: &mut F,
  253. path_segment: &PathSegment)
  254. -> PathSegment {
  255. panic!();
  256.  
  257. }
  258. pub fn noop_fold_path_parameters<F: Folder>(folder: &mut F,
  259. path_parameters: &PathParameters)
  260. -> PathParameters {
  261. panic!();
  262.  
  263. }
  264. pub fn noop_fold_assoc_type_binding<F: Folder>(folder: &mut F,
  265. type_binding: &TypeBinding)
  266. -> TypeBinding {
  267. panic!();
  268.  
  269. }
  270. pub fn noop_fold_attribute<F: Folder>(_: &mut F, _attr: &Attribute) -> Attribute {
  271. _attr
  272.  
  273. }
  274. pub fn noop_fold_fn_ret_ty<F: Folder>(folder: &mut F, ret_ty: &FunctionRetTy) -> FunctionRetTy {
  275. panic!();
  276.  
  277. }
  278. pub fn noop_fold_const_expr<F: Folder>(folder: &mut F, expr: &ConstExpr) -> ConstExpr {
  279. panic!();
  280.  
  281. }
  282. pub fn noop_fold_lit<F: Folder>(folder: &mut F, _lit: &Lit) -> Lit {
  283. panic!();
  284.  
  285. }
  286.  
  287. pub fn noop_fold_mac<F: Folder>(folder: &mut F, mac: &Mac) -> Mac {
  288. panic!();
  289.  
  290. }
  291.  
  292. #[cfg(feature = "full")]
  293. pub fn noop_fold_crate<F: Folder>(folder: &mut F, _crate: &Crate) -> Crate {
  294. panic!();
  295.  
  296. }
  297. #[cfg(feature = "full")]
  298. pub fn noop_fold_item<F: Folder>(folder: &mut F, item: &Item) -> Item {
  299. panic!();
  300.  
  301. }
  302. #[cfg(feature = "full")]
  303. pub fn noop_fold_expr<F: Folder>(folder: &mut F, expr: &Expr) -> Expr {
  304. panic!();
  305.  
  306. }
  307. #[cfg(feature = "full")]
  308. pub fn noop_fold_foreign_item<F: Folder>(folder: &mut F,
  309. foreign_item: &ForeignItem)
  310. -> ForeignItem {
  311. panic!();
  312.  
  313. }
  314. #[cfg(feature = "full")]
  315. pub fn noop_fold_pat<F: Folder>(folder: &mut F, pat: &Pat) -> Pat {
  316. panic!();
  317.  
  318. }
  319. #[cfg(feature = "full")]
  320. pub fn noop_fold_fn_decl<F: Folder>(folder: &mut F, fn_decl: &FnDecl) -> FnDecl {
  321. panic!();
  322.  
  323. }
  324. #[cfg(feature = "full")]
  325. pub fn noop_fold_trait_item<F: Folder>(folder: &mut F, trait_item: &TraitItem) -> TraitItem {
  326. panic!();
  327.  
  328. }
  329. #[cfg(feature = "full")]
  330. pub fn noop_fold_impl_item<F: Folder>(folder: &mut F, impl_item: &ImplItem) -> ImplItem {
  331. panic!();
  332.  
  333. }
  334. #[cfg(feature = "full")]
  335. pub fn noop_fold_method_sig<F: Folder>(folder: &mut F, method_sig: &MethodSig) -> MethodSig {
  336. panic!();
  337.  
  338. }
  339. #[cfg(feature = "full")]
  340. pub fn noop_fold_stmt<F: Folder>(folder: &mut F, stmt: &Stmt) -> Stmt {
  341. panic!();
  342.  
  343. }
  344. #[cfg(feature = "full")]
  345. pub fn noop_fold_local<F: Folder>(folder: &mut F, local: &Local) -> Local {
  346. panic!();
  347.  
  348. }
  349. #[cfg(feature = "full")]
  350. pub fn noop_fold_view_path<F: Folder>(folder: &mut F, view_path: &ViewPath) -> ViewPath {
  351. panic!();
  352.  
  353. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement