@@ -16,7 +16,7 @@ use rustc_metadata::cstore::CStore;
16
16
use rustc_mir:: util:: { write_mir_pretty, write_mir_graphviz} ;
17
17
18
18
use syntax:: ast:: { self , BlockCheckMode } ;
19
- use syntax:: fold :: { self , Folder } ;
19
+ use syntax:: mut_visit :: { * , MutVisitor , visit_clobber } ;
20
20
use syntax:: print:: { pprust} ;
21
21
use syntax:: print:: pprust:: PrintState ;
22
22
use syntax:: ptr:: P ;
@@ -28,6 +28,7 @@ use smallvec::SmallVec;
28
28
use std:: cell:: Cell ;
29
29
use std:: fs:: File ;
30
30
use std:: io:: { self , Write } ;
31
+ use std:: ops:: DerefMut ;
31
32
use std:: option;
32
33
use std:: path:: Path ;
33
34
use std:: str:: FromStr ;
@@ -703,42 +704,42 @@ impl<'a> ReplaceBodyWithLoop<'a> {
703
704
}
704
705
}
705
706
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 ) {
708
709
let is_const = match i {
709
710
ast:: ItemKind :: Static ( ..) | ast:: ItemKind :: Const ( ..) => true ,
710
711
ast:: ItemKind :: Fn ( ref decl, ref header, _, _) =>
711
712
header. constness . node == ast:: Constness :: Const || Self :: should_ignore_fn ( decl) ,
712
713
_ => false ,
713
714
} ;
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) )
715
716
}
716
717
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 ] > {
718
719
let is_const = match i. node {
719
720
ast:: TraitItemKind :: Const ( ..) => true ,
720
721
ast:: TraitItemKind :: Method ( ast:: MethodSig { ref decl, ref header, .. } , _) =>
721
722
header. constness . node == ast:: Constness :: Const || Self :: should_ignore_fn ( decl) ,
722
723
_ => false ,
723
724
} ;
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) )
725
726
}
726
727
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 ] > {
728
729
let is_const = match i. node {
729
730
ast:: ImplItemKind :: Const ( ..) => true ,
730
731
ast:: ImplItemKind :: Method ( ast:: MethodSig { ref decl, ref header, .. } , _) =>
731
732
header. constness . node == ast:: Constness :: Const || Self :: should_ignore_fn ( decl) ,
732
733
_ => false ,
733
734
} ;
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) )
735
736
}
736
737
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) )
739
740
}
740
741
741
- fn fold_block ( & mut self , b : P < ast :: Block > ) -> P < ast:: Block > {
742
+ fn visit_block ( & mut self , b : & mut P < ast:: Block > ) {
742
743
fn stmt_to_block ( rules : ast:: BlockCheckMode ,
743
744
s : Option < ast:: Stmt > ,
744
745
sess : & Session ) -> ast:: Block {
@@ -780,14 +781,14 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
780
781
} ;
781
782
782
783
if self . within_static_or_const {
783
- fold :: noop_fold_block ( b, self )
784
+ noop_visit_block ( b, self )
784
785
} else {
785
- b . map ( |b| {
786
+ visit_clobber ( b . deref_mut ( ) , |b| {
786
787
let mut stmts = vec ! [ ] ;
787
788
for s in b. stmts {
788
789
let old_blocks = self . nested_blocks . replace ( vec ! [ ] ) ;
789
790
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 ( ) ) ) ;
791
792
792
793
// we put a Some in there earlier with that replace(), so this is valid
793
794
let new_blocks = self . nested_blocks . take ( ) . unwrap ( ) ;
@@ -818,9 +819,9 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
818
819
}
819
820
820
821
// 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 )
824
825
}
825
826
}
826
827
@@ -889,12 +890,9 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec<borrowck_dot::Variant>,
889
890
}
890
891
}
891
892
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 ) {
893
894
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) ;
898
896
}
899
897
}
900
898
0 commit comments