@@ -18,7 +18,7 @@ use rustc_mir;
18
18
use rustc_passes;
19
19
use rustc_plugin;
20
20
use rustc_privacy;
21
- use rustc_resolve;
21
+ use rustc_resolve:: { self , Resolver } ;
22
22
use rustc_typeck;
23
23
use std:: env;
24
24
use std:: env:: consts:: { DLL_PREFIX , DLL_SUFFIX } ;
@@ -715,18 +715,18 @@ pub fn build_output_filenames(
715
715
// ambitious form of the closed RFC #1637. See also [#34511].
716
716
//
717
717
// [#34511]: https://github.com/rust-lang/rust/issues/34511#issuecomment-322340401
718
- pub struct ReplaceBodyWithLoop < ' a > {
718
+ pub struct ReplaceBodyWithLoop < ' a , ' b > {
719
719
within_static_or_const : bool ,
720
720
nested_blocks : Option < Vec < ast:: Block > > ,
721
- sess : & ' a Session ,
721
+ resolver : & ' a mut Resolver < ' b > ,
722
722
}
723
723
724
- impl < ' a > ReplaceBodyWithLoop < ' a > {
725
- pub fn new ( sess : & ' a Session ) -> ReplaceBodyWithLoop < ' a > {
724
+ impl < ' a , ' b > ReplaceBodyWithLoop < ' a , ' b > {
725
+ pub fn new ( resolver : & ' a mut Resolver < ' b > ) -> ReplaceBodyWithLoop < ' a , ' b > {
726
726
ReplaceBodyWithLoop {
727
727
within_static_or_const : false ,
728
728
nested_blocks : None ,
729
- sess
729
+ resolver ,
730
730
}
731
731
}
732
732
@@ -788,11 +788,12 @@ impl<'a> ReplaceBodyWithLoop<'a> {
788
788
}
789
789
790
790
fn is_sig_const ( sig : & ast:: FnSig ) -> bool {
791
- sig. header . constness . node == ast:: Constness :: Const || Self :: should_ignore_fn ( & sig. decl )
791
+ sig. header . constness . node == ast:: Constness :: Const ||
792
+ ReplaceBodyWithLoop :: should_ignore_fn ( & sig. decl )
792
793
}
793
794
}
794
795
795
- impl < ' a > MutVisitor for ReplaceBodyWithLoop < ' a > {
796
+ impl < ' a > MutVisitor for ReplaceBodyWithLoop < ' a , ' _ > {
796
797
fn visit_item_kind ( & mut self , i : & mut ast:: ItemKind ) {
797
798
let is_const = match i {
798
799
ast:: ItemKind :: Static ( ..) | ast:: ItemKind :: Const ( ..) => true ,
@@ -827,40 +828,40 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a> {
827
828
fn visit_block ( & mut self , b : & mut P < ast:: Block > ) {
828
829
fn stmt_to_block ( rules : ast:: BlockCheckMode ,
829
830
s : Option < ast:: Stmt > ,
830
- sess : & Session ) -> ast:: Block {
831
+ resolver : & mut Resolver < ' _ > ) -> ast:: Block {
831
832
ast:: Block {
832
833
stmts : s. into_iter ( ) . collect ( ) ,
833
834
rules,
834
- id : sess . next_node_id ( ) ,
835
+ id : resolver . next_node_id ( ) ,
835
836
span : syntax_pos:: DUMMY_SP ,
836
837
}
837
838
}
838
839
839
- fn block_to_stmt ( b : ast:: Block , sess : & Session ) -> ast:: Stmt {
840
+ fn block_to_stmt ( b : ast:: Block , resolver : & mut Resolver < ' _ > ) -> ast:: Stmt {
840
841
let expr = P ( ast:: Expr {
841
- id : sess . next_node_id ( ) ,
842
+ id : resolver . next_node_id ( ) ,
842
843
kind : ast:: ExprKind :: Block ( P ( b) , None ) ,
843
844
span : syntax_pos:: DUMMY_SP ,
844
845
attrs : ThinVec :: new ( ) ,
845
846
} ) ;
846
847
847
848
ast:: Stmt {
848
- id : sess . next_node_id ( ) ,
849
+ id : resolver . next_node_id ( ) ,
849
850
kind : ast:: StmtKind :: Expr ( expr) ,
850
851
span : syntax_pos:: DUMMY_SP ,
851
852
}
852
853
}
853
854
854
- let empty_block = stmt_to_block ( BlockCheckMode :: Default , None , self . sess ) ;
855
+ let empty_block = stmt_to_block ( BlockCheckMode :: Default , None , self . resolver ) ;
855
856
let loop_expr = P ( ast:: Expr {
856
857
kind : ast:: ExprKind :: Loop ( P ( empty_block) , None ) ,
857
- id : self . sess . next_node_id ( ) ,
858
+ id : self . resolver . next_node_id ( ) ,
858
859
span : syntax_pos:: DUMMY_SP ,
859
860
attrs : ThinVec :: new ( ) ,
860
861
} ) ;
861
862
862
863
let loop_stmt = ast:: Stmt {
863
- id : self . sess . next_node_id ( ) ,
864
+ id : self . resolver . next_node_id ( ) ,
864
865
span : syntax_pos:: DUMMY_SP ,
865
866
kind : ast:: StmtKind :: Expr ( loop_expr) ,
866
867
} ;
@@ -878,7 +879,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a> {
878
879
// we put a Some in there earlier with that replace(), so this is valid
879
880
let new_blocks = self . nested_blocks . take ( ) . unwrap ( ) ;
880
881
self . nested_blocks = old_blocks;
881
- stmts. extend ( new_blocks. into_iter ( ) . map ( |b| block_to_stmt ( b, & self . sess ) ) ) ;
882
+ stmts. extend ( new_blocks. into_iter ( ) . map ( |b| block_to_stmt ( b, self . resolver ) ) ) ;
882
883
}
883
884
884
885
let mut new_block = ast:: Block {
@@ -892,7 +893,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a> {
892
893
old_blocks. push ( new_block) ;
893
894
}
894
895
895
- stmt_to_block ( b. rules , Some ( loop_stmt) , self . sess )
896
+ stmt_to_block ( b. rules , Some ( loop_stmt) , & mut self . resolver )
896
897
} else {
897
898
//push `loop {}` onto the end of our fresh block and yield that
898
899
new_block. stmts . push ( loop_stmt) ;
0 commit comments