From faa82eb46c800857756ddc5458623a906a9f103e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 5 Feb 2019 15:10:04 +1100 Subject: [PATCH] Streamline `Folder`. Specifically: - Remove dead methods: fold_usize, fold_meta_items, fold_opt_bounds. - Remove useless methods: fold_global_asm, fold_range_end. - Inline and remove unnecessary methods: fold_item_simple, fold_foreign_item_simple. --- src/libsyntax/fold.rs | 95 +++++++++---------------------------------- 1 file changed, 19 insertions(+), 76 deletions(-) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index d8afad5e379..6f856f63d6c 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -45,10 +45,6 @@ pub trait Folder : Sized { noop_fold_crate(c, self) } - fn fold_meta_items(&mut self, meta_items: Vec) -> Vec { - noop_fold_meta_items(meta_items, self) - } - fn fold_meta_list_item(&mut self, list_item: NestedMetaItem) -> NestedMetaItem { noop_fold_meta_list_item(list_item, self) } @@ -65,18 +61,10 @@ pub trait Folder : Sized { noop_fold_foreign_item(ni, self) } - fn fold_foreign_item_simple(&mut self, ni: ForeignItem) -> ForeignItem { - noop_fold_foreign_item_simple(ni, self) - } - fn fold_item(&mut self, i: P) -> SmallVec<[P; 1]> { noop_fold_item(i, self) } - fn fold_item_simple(&mut self, i: Item) -> Item { - noop_fold_item_simple(i, self) - } - fn fold_fn_header(&mut self, header: FnHeader) -> FnHeader { noop_fold_fn_header(header, self) } @@ -133,10 +121,6 @@ pub trait Folder : Sized { e.map(|e| noop_fold_expr(e, self)) } - fn fold_range_end(&mut self, re: RangeEnd) -> RangeEnd { - noop_fold_range_end(re, self) - } - fn fold_opt_expr(&mut self, e: P) -> Option> { noop_fold_opt_expr(e, self) } @@ -172,10 +156,6 @@ pub trait Folder : Sized { noop_fold_foreign_mod(nm, self) } - fn fold_global_asm(&mut self, ga: P) -> P { - noop_fold_global_asm(ga, self) - } - fn fold_variant(&mut self, v: Variant) -> Variant { noop_fold_variant(v, self) } @@ -184,10 +164,6 @@ pub trait Folder : Sized { noop_fold_ident(i, self) } - fn fold_usize(&mut self, i: usize) -> usize { - noop_fold_usize(i, self) - } - fn fold_path(&mut self, p: Path) -> Path { noop_fold_path(p, self) } @@ -281,10 +257,6 @@ pub trait Folder : Sized { noop_fold_interpolated(nt, self) } - fn fold_opt_bounds(&mut self, b: Option) -> Option { - noop_fold_opt_bounds(b, self) - } - fn fold_bounds(&mut self, b: GenericBounds) -> GenericBounds { noop_fold_bounds(b, self) } @@ -324,10 +296,6 @@ pub trait Folder : Sized { } } -pub fn noop_fold_meta_items(meta_items: Vec, fld: &mut T) -> Vec { - meta_items.move_map(|x| fld.fold_meta_item(x)) -} - pub fn noop_fold_use_tree(use_tree: UseTree, fld: &mut T) -> UseTree { UseTree { span: fld.new_span(use_tree.span), @@ -430,11 +398,6 @@ pub fn noop_fold_foreign_mod(ForeignMod {abi, items}: ForeignMod, } } -pub fn noop_fold_global_asm(ga: P, - _: &mut T) -> P { - ga -} - pub fn noop_fold_variant(v: Variant, fld: &mut T) -> Variant { Spanned { node: Variant_ { @@ -451,10 +414,6 @@ pub fn noop_fold_ident(ident: Ident, fld: &mut T) -> Ident { Ident::new(ident.name, fld.new_span(ident.span)) } -pub fn noop_fold_usize(i: usize, _: &mut T) -> usize { - i -} - pub fn noop_fold_path(Path { segments, span }: Path, fld: &mut T) -> Path { Path { segments: segments.move_map(|PathSegment { ident, id, args }| PathSegment { @@ -873,11 +832,6 @@ pub fn noop_fold_mt(MutTy {ty, mutbl}: MutTy, folder: &mut T) -> MutT } } -pub fn noop_fold_opt_bounds(b: Option, folder: &mut T) - -> Option { - b.map(|bounds| folder.fold_bounds(bounds)) -} - fn noop_fold_bounds(bounds: GenericBounds, folder: &mut T) -> GenericBounds { bounds.move_map(|bound| folder.fold_param_bound(bound)) @@ -913,7 +867,7 @@ pub fn noop_fold_item_kind(i: ItemKind, folder: &mut T) -> ItemKind { } ItemKind::Mod(m) => ItemKind::Mod(folder.fold_mod(m)), ItemKind::ForeignMod(nm) => ItemKind::ForeignMod(folder.fold_foreign_mod(nm)), - ItemKind::GlobalAsm(ga) => ItemKind::GlobalAsm(folder.fold_global_asm(ga)), + ItemKind::GlobalAsm(ga) => ItemKind::GlobalAsm(ga), ItemKind::Ty(t, generics) => { ItemKind::Ty(folder.fold_ty(t), folder.fold_generics(generics)) } @@ -1071,34 +1025,27 @@ pub fn noop_fold_crate(Crate {module, attrs, span}: Crate, // fold one item into possibly many items pub fn noop_fold_item(i: P, folder: &mut T) -> SmallVec<[P; 1]> { - smallvec![i.map(|i| folder.fold_item_simple(i))] -} + smallvec![i.map(|i| { + let Item {id, ident, attrs, node, vis, span, tokens} = i; + Item { + id: folder.new_id(id), + vis: folder.fold_vis(vis), + ident: folder.fold_ident(ident), + attrs: fold_attrs(attrs, folder), + node: folder.fold_item_kind(node), + span: folder.new_span(span), -// fold one item into exactly one item -pub fn noop_fold_item_simple(Item {id, ident, attrs, node, vis, span, tokens}: Item, - folder: &mut T) -> Item { - Item { - id: folder.new_id(id), - vis: folder.fold_vis(vis), - ident: folder.fold_ident(ident), - attrs: fold_attrs(attrs, folder), - node: folder.fold_item_kind(node), - span: folder.new_span(span), - - // FIXME: if this is replaced with a call to `folder.fold_tts` it causes - // an ICE during resolve... odd! - tokens, - } + // FIXME: if this is replaced with a call to `folder.fold_tts` it causes + // an ICE during resolve... odd! + tokens, + } + })] } pub fn noop_fold_foreign_item(ni: ForeignItem, folder: &mut T) -> SmallVec<[ForeignItem; 1]> { - smallvec![folder.fold_foreign_item_simple(ni)] -} - -pub fn noop_fold_foreign_item_simple(ni: ForeignItem, folder: &mut T) -> ForeignItem { - ForeignItem { + smallvec![ForeignItem { id: folder.new_id(ni.id), vis: folder.fold_vis(ni.vis), ident: folder.fold_ident(ni.ident), @@ -1114,7 +1061,7 @@ pub fn noop_fold_foreign_item_simple(ni: ForeignItem, folder: &mut T) ForeignItemKind::Macro(mac) => ForeignItemKind::Macro(folder.fold_mac(mac)), }, span: folder.new_span(ni.span) - } + }] } pub fn noop_fold_method_sig(sig: MethodSig, folder: &mut T) -> MethodSig { @@ -1161,10 +1108,10 @@ pub fn noop_fold_pat(p: P, folder: &mut T) -> P { } PatKind::Box(inner) => PatKind::Box(folder.fold_pat(inner)), PatKind::Ref(inner, mutbl) => PatKind::Ref(folder.fold_pat(inner), mutbl), - PatKind::Range(e1, e2, Spanned { span, node: end }) => { + PatKind::Range(e1, e2, Spanned { span, node }) => { PatKind::Range(folder.fold_expr(e1), folder.fold_expr(e2), - Spanned { span, node: folder.fold_range_end(end) }) + Spanned { span, node }) }, PatKind::Slice(before, slice, after) => { PatKind::Slice(before.move_map(|x| folder.fold_pat(x)), @@ -1178,10 +1125,6 @@ pub fn noop_fold_pat(p: P, folder: &mut T) -> P { }) } -pub fn noop_fold_range_end(end: RangeEnd, _folder: &mut T) -> RangeEnd { - end -} - pub fn noop_fold_anon_const(constant: AnonConst, folder: &mut T) -> AnonConst { let AnonConst {id, value} = constant; AnonConst {