@@ -20,7 +20,7 @@ use rustc_middle::mir::*;
20
20
use rustc_middle:: thir:: {
21
21
self , BindingMode , Expr , ExprId , LintLevel , LocalVarId , Param , ParamId , PatKind , Thir ,
22
22
} ;
23
- use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeVisitableExt , TypeckResults } ;
23
+ use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeVisitableExt } ;
24
24
use rustc_span:: symbol:: sym;
25
25
use rustc_span:: Span ;
26
26
use rustc_span:: Symbol ;
@@ -155,13 +155,13 @@ struct BlockContext(Vec<BlockFrame>);
155
155
struct Builder < ' a , ' tcx > {
156
156
tcx : TyCtxt < ' tcx > ,
157
157
infcx : InferCtxt < ' tcx > ,
158
- typeck_results : & ' tcx TypeckResults < ' tcx > ,
159
158
region_scope_tree : & ' tcx region:: ScopeTree ,
160
159
param_env : ty:: ParamEnv < ' tcx > ,
161
160
162
161
thir : & ' a Thir < ' tcx > ,
163
162
cfg : CFG < ' tcx > ,
164
163
164
+ def : ty:: WithOptConstParam < LocalDefId > ,
165
165
def_id : DefId ,
166
166
hir_id : hir:: HirId ,
167
167
parent_module : DefId ,
@@ -522,13 +522,7 @@ fn construct_fn<'tcx>(
522
522
let return_block =
523
523
unpack!( builder. in_breakable_scope( None , Place :: return_place( ) , fn_end, |builder| {
524
524
Some ( builder. in_scope( arg_scope_s, LintLevel :: Inherited , |builder| {
525
- builder. args_and_body(
526
- START_BLOCK ,
527
- fn_def. did,
528
- arguments,
529
- arg_scope,
530
- & thir[ expr] ,
531
- )
525
+ builder. args_and_body( START_BLOCK , arguments, arg_scope, & thir[ expr] )
532
526
} ) )
533
527
} ) ) ;
534
528
let source_info = builder. source_info( fn_end) ;
@@ -704,9 +698,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
704
698
thir,
705
699
tcx,
706
700
infcx,
707
- typeck_results : tcx. typeck_opt_const_arg ( def) ,
708
701
region_scope_tree : tcx. region_scope_tree ( def. did ) ,
709
702
param_env,
703
+ def,
710
704
def_id : def. did . to_def_id ( ) ,
711
705
hir_id,
712
706
parent_module : tcx. parent_module ( hir_id) . to_def_id ( ) ,
@@ -756,14 +750,78 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
756
750
self . var_debug_info ,
757
751
self . fn_span ,
758
752
self . generator_kind ,
759
- self . typeck_results . tainted_by_errors ,
753
+ None ,
760
754
)
761
755
}
762
756
757
+ fn insert_upvar_arg ( & mut self ) {
758
+ let Some ( closure_arg) = self . local_decls . get ( ty:: CAPTURE_STRUCT_LOCAL ) else { return } ;
759
+
760
+ let mut closure_ty = closure_arg. ty ;
761
+ let mut closure_env_projs = vec ! [ ] ;
762
+ if let ty:: Ref ( _, ty, _) = closure_ty. kind ( ) {
763
+ closure_env_projs. push ( ProjectionElem :: Deref ) ;
764
+ closure_ty = * ty;
765
+ }
766
+
767
+ let upvar_substs = match closure_ty. kind ( ) {
768
+ ty:: Closure ( _, substs) => ty:: UpvarSubsts :: Closure ( substs) ,
769
+ ty:: Generator ( _, substs, _) => ty:: UpvarSubsts :: Generator ( substs) ,
770
+ _ => return ,
771
+ } ;
772
+
773
+ // In analyze_closure() in upvar.rs we gathered a list of upvars used by an
774
+ // indexed closure and we stored in a map called closure_min_captures in TypeckResults
775
+ // with the closure's DefId. Here, we run through that vec of UpvarIds for
776
+ // the given closure and use the necessary information to create upvar
777
+ // debuginfo and to fill `self.upvars`.
778
+ let capture_tys = upvar_substs. upvar_tys ( ) ;
779
+
780
+ let tcx = self . tcx ;
781
+ self . upvars = tcx
782
+ . closure_captures ( self . def . did )
783
+ . iter ( )
784
+ . zip ( capture_tys)
785
+ . enumerate ( )
786
+ . map ( |( i, ( captured_place, ty) ) | {
787
+ let name = captured_place. to_symbol ( ) ;
788
+
789
+ let capture = captured_place. info . capture_kind ;
790
+ let var_id = match captured_place. place . base {
791
+ HirPlaceBase :: Upvar ( upvar_id) => upvar_id. var_path . hir_id ,
792
+ _ => bug ! ( "Expected an upvar" ) ,
793
+ } ;
794
+
795
+ let mutability = captured_place. mutability ;
796
+
797
+ let mut projs = closure_env_projs. clone ( ) ;
798
+ projs. push ( ProjectionElem :: Field ( Field :: new ( i) , ty) ) ;
799
+ match capture {
800
+ ty:: UpvarCapture :: ByValue => { }
801
+ ty:: UpvarCapture :: ByRef ( ..) => {
802
+ projs. push ( ProjectionElem :: Deref ) ;
803
+ }
804
+ } ;
805
+
806
+ let use_place = Place {
807
+ local : ty:: CAPTURE_STRUCT_LOCAL ,
808
+ projection : tcx. mk_place_elems ( & projs) ,
809
+ } ;
810
+ self . var_debug_info . push ( VarDebugInfo {
811
+ name,
812
+ source_info : SourceInfo :: outermost ( captured_place. var_ident . span ) ,
813
+ value : VarDebugInfoContents :: Place ( use_place) ,
814
+ } ) ;
815
+
816
+ let capture = Capture { captured_place, use_place, mutability } ;
817
+ ( var_id, capture)
818
+ } )
819
+ . collect ( ) ;
820
+ }
821
+
763
822
fn args_and_body (
764
823
& mut self ,
765
824
mut block : BasicBlock ,
766
- fn_def_id : LocalDefId ,
767
825
arguments : & IndexVec < ParamId , Param < ' tcx > > ,
768
826
argument_scope : region:: Scope ,
769
827
expr : & Expr < ' tcx > ,
@@ -785,69 +843,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
785
843
}
786
844
}
787
845
788
- let tcx = self . tcx ;
789
- let tcx_hir = tcx. hir ( ) ;
790
- let hir_typeck_results = self . typeck_results ;
791
-
792
- // In analyze_closure() in upvar.rs we gathered a list of upvars used by an
793
- // indexed closure and we stored in a map called closure_min_captures in TypeckResults
794
- // with the closure's DefId. Here, we run through that vec of UpvarIds for
795
- // the given closure and use the necessary information to create upvar
796
- // debuginfo and to fill `self.upvars`.
797
- if hir_typeck_results. closure_min_captures . get ( & fn_def_id) . is_some ( ) {
798
- let mut closure_env_projs = vec ! [ ] ;
799
- let mut closure_ty = self . local_decls [ ty:: CAPTURE_STRUCT_LOCAL ] . ty ;
800
- if let ty:: Ref ( _, ty, _) = closure_ty. kind ( ) {
801
- closure_env_projs. push ( ProjectionElem :: Deref ) ;
802
- closure_ty = * ty;
803
- }
804
- let upvar_substs = match closure_ty. kind ( ) {
805
- ty:: Closure ( _, substs) => ty:: UpvarSubsts :: Closure ( substs) ,
806
- ty:: Generator ( _, substs, _) => ty:: UpvarSubsts :: Generator ( substs) ,
807
- _ => span_bug ! ( self . fn_span, "upvars with non-closure env ty {:?}" , closure_ty) ,
808
- } ;
809
- let def_id = self . def_id . as_local ( ) . unwrap ( ) ;
810
- let capture_syms = tcx. symbols_for_closure_captures ( ( def_id, fn_def_id) ) ;
811
- let capture_tys = upvar_substs. upvar_tys ( ) ;
812
- let captures_with_tys = hir_typeck_results
813
- . closure_min_captures_flattened ( fn_def_id)
814
- . zip ( capture_tys. zip ( capture_syms) ) ;
815
-
816
- self . upvars = captures_with_tys
817
- . enumerate ( )
818
- . map ( |( i, ( captured_place, ( ty, sym) ) ) | {
819
- let capture = captured_place. info . capture_kind ;
820
- let var_id = match captured_place. place . base {
821
- HirPlaceBase :: Upvar ( upvar_id) => upvar_id. var_path . hir_id ,
822
- _ => bug ! ( "Expected an upvar" ) ,
823
- } ;
824
-
825
- let mutability = captured_place. mutability ;
826
-
827
- let mut projs = closure_env_projs. clone ( ) ;
828
- projs. push ( ProjectionElem :: Field ( Field :: new ( i) , ty) ) ;
829
- match capture {
830
- ty:: UpvarCapture :: ByValue => { }
831
- ty:: UpvarCapture :: ByRef ( ..) => {
832
- projs. push ( ProjectionElem :: Deref ) ;
833
- }
834
- } ;
835
-
836
- let use_place = Place {
837
- local : ty:: CAPTURE_STRUCT_LOCAL ,
838
- projection : tcx. mk_place_elems ( & projs) ,
839
- } ;
840
- self . var_debug_info . push ( VarDebugInfo {
841
- name : * sym,
842
- source_info : SourceInfo :: outermost ( tcx_hir. span ( var_id) ) ,
843
- value : VarDebugInfoContents :: Place ( use_place) ,
844
- } ) ;
845
-
846
- let capture = Capture { captured_place, use_place, mutability } ;
847
- ( var_id, capture)
848
- } )
849
- . collect ( ) ;
850
- }
846
+ self . insert_upvar_arg ( ) ;
851
847
852
848
let mut scope = None ;
853
849
// Bind the argument patterns
0 commit comments