@@ -16,7 +16,7 @@ use rustc_metadata::cstore::CStore;
1616use rustc_mir:: util:: { write_mir_pretty, write_mir_graphviz} ;
1717
1818use syntax:: ast:: { self , BlockCheckMode } ;
19- use syntax:: fold :: { self , Folder } ;
19+ use syntax:: mut_visit :: { * , MutVisitor , visit_clobber } ;
2020use syntax:: print:: { pprust} ;
2121use syntax:: print:: pprust:: PrintState ;
2222use syntax:: ptr:: P ;
@@ -28,6 +28,7 @@ use smallvec::SmallVec;
2828use std:: cell:: Cell ;
2929use std:: fs:: File ;
3030use std:: io:: { self , Write } ;
31+ use std:: ops:: DerefMut ;
3132use std:: option;
3233use std:: path:: Path ;
3334use std:: str:: FromStr ;
@@ -703,42 +704,42 @@ impl<'a> ReplaceBodyWithLoop<'a> {
703704 }
704705}
705706
706- impl < ' a > fold :: Folder for ReplaceBodyWithLoop < ' a > {
707- fn fold_item_kind ( & mut self , i : ast :: ItemKind ) -> ast:: ItemKind {
707+ impl < ' a > MutVisitor for ReplaceBodyWithLoop < ' a > {
708+ fn visit_item_kind ( & mut self , i : & mut ast:: ItemKind ) {
708709 let is_const = match i {
709710 ast:: ItemKind :: Static ( ..) | ast:: ItemKind :: Const ( ..) => true ,
710711 ast:: ItemKind :: Fn ( ref decl, ref header, _, _) =>
711712 header. constness . node == ast:: Constness :: Const || Self :: should_ignore_fn ( decl) ,
712713 _ => false ,
713714 } ;
714- self . run ( is_const, |s| fold :: noop_fold_item_kind ( i, s) )
715+ self . run ( is_const, |s| noop_visit_item_kind ( i, s) )
715716 }
716717
717- fn fold_trait_item ( & mut self , i : ast:: TraitItem ) -> SmallVec < [ ast:: TraitItem ; 1 ] > {
718+ fn flat_map_trait_item ( & mut self , i : ast:: TraitItem ) -> SmallVec < [ ast:: TraitItem ; 1 ] > {
718719 let is_const = match i. node {
719720 ast:: TraitItemKind :: Const ( ..) => true ,
720721 ast:: TraitItemKind :: Method ( ast:: MethodSig { ref decl, ref header, .. } , _) =>
721722 header. constness . node == ast:: Constness :: Const || Self :: should_ignore_fn ( decl) ,
722723 _ => false ,
723724 } ;
724- self . run ( is_const, |s| fold :: noop_fold_trait_item ( i, s) )
725+ self . run ( is_const, |s| noop_flat_map_trait_item ( i, s) )
725726 }
726727
727- fn fold_impl_item ( & mut self , i : ast:: ImplItem ) -> SmallVec < [ ast:: ImplItem ; 1 ] > {
728+ fn flat_map_impl_item ( & mut self , i : ast:: ImplItem ) -> SmallVec < [ ast:: ImplItem ; 1 ] > {
728729 let is_const = match i. node {
729730 ast:: ImplItemKind :: Const ( ..) => true ,
730731 ast:: ImplItemKind :: Method ( ast:: MethodSig { ref decl, ref header, .. } , _) =>
731732 header. constness . node == ast:: Constness :: Const || Self :: should_ignore_fn ( decl) ,
732733 _ => false ,
733734 } ;
734- self . run ( is_const, |s| fold :: noop_fold_impl_item ( i, s) )
735+ self . run ( is_const, |s| noop_flat_map_impl_item ( i, s) )
735736 }
736737
737- fn fold_anon_const ( & mut self , c : ast :: AnonConst ) -> ast:: AnonConst {
738- self . run ( true , |s| fold :: noop_fold_anon_const ( c, s) )
738+ fn visit_anon_const ( & mut self , c : & mut ast:: AnonConst ) {
739+ self . run ( true , |s| noop_visit_anon_const ( c, s) )
739740 }
740741
741- fn fold_block ( & mut self , b : P < ast :: Block > ) -> P < ast:: Block > {
742+ fn visit_block ( & mut self , b : & mut P < ast:: Block > ) {
742743 fn stmt_to_block ( rules : ast:: BlockCheckMode ,
743744 s : Option < ast:: Stmt > ,
744745 sess : & Session ) -> ast:: Block {
@@ -780,14 +781,14 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
780781 } ;
781782
782783 if self . within_static_or_const {
783- fold :: noop_fold_block ( b, self )
784+ noop_visit_block ( b, self )
784785 } else {
785- b . map ( |b| {
786+ visit_clobber ( b . deref_mut ( ) , |b| {
786787 let mut stmts = vec ! [ ] ;
787788 for s in b. stmts {
788789 let old_blocks = self . nested_blocks . replace ( vec ! [ ] ) ;
789790
790- stmts. extend ( self . fold_stmt ( s) . into_iter ( ) . filter ( |s| s. is_item ( ) ) ) ;
791+ stmts. extend ( self . flat_map_stmt ( s) . into_iter ( ) . filter ( |s| s. is_item ( ) ) ) ;
791792
792793 // we put a Some in there earlier with that replace(), so this is valid
793794 let new_blocks = self . nested_blocks . take ( ) . unwrap ( ) ;
@@ -818,9 +819,9 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
818819 }
819820
820821 // in general the pretty printer processes unexpanded code, so
821- // we override the default `fold_mac ` method which panics.
822- fn fold_mac ( & mut self , mac : ast :: Mac ) -> ast:: Mac {
823- fold :: noop_fold_mac ( mac, self )
822+ // we override the default `visit_mac ` method which panics.
823+ fn visit_mac ( & mut self , mac : & mut ast:: Mac ) {
824+ noop_visit_mac ( mac, self )
824825 }
825826}
826827
@@ -889,12 +890,9 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec<borrowck_dot::Variant>,
889890 }
890891}
891892
892- pub fn fold_crate ( sess : & Session , krate : ast:: Crate , ppm : PpMode ) -> ast :: Crate {
893+ pub fn visit_crate ( sess : & Session , krate : & mut ast:: Crate , ppm : PpMode ) {
893894 if let PpmSource ( PpmEveryBodyLoops ) = ppm {
894- let mut fold = ReplaceBodyWithLoop :: new ( sess) ;
895- fold. fold_crate ( krate)
896- } else {
897- krate
895+ ReplaceBodyWithLoop :: new ( sess) . visit_crate ( krate) ;
898896 }
899897}
900898
0 commit comments