@@ -20,7 +20,7 @@ use rustc_middle::mir::*;
2020use rustc_middle:: thir:: {
2121 self , BindingMode , Expr , ExprId , LintLevel , LocalVarId , Param , ParamId , PatKind , Thir ,
2222} ;
23- use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeVisitableExt , TypeckResults } ;
23+ use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeVisitableExt } ;
2424use rustc_span:: symbol:: sym;
2525use rustc_span:: Span ;
2626use rustc_span:: Symbol ;
@@ -155,13 +155,13 @@ struct BlockContext(Vec<BlockFrame>);
155155struct Builder < ' a , ' tcx > {
156156 tcx : TyCtxt < ' tcx > ,
157157 infcx : InferCtxt < ' tcx > ,
158- typeck_results : & ' tcx TypeckResults < ' tcx > ,
159158 region_scope_tree : & ' tcx region:: ScopeTree ,
160159 param_env : ty:: ParamEnv < ' tcx > ,
161160
162161 thir : & ' a Thir < ' tcx > ,
163162 cfg : CFG < ' tcx > ,
164163
164+ def : ty:: WithOptConstParam < LocalDefId > ,
165165 def_id : DefId ,
166166 hir_id : hir:: HirId ,
167167 parent_module : DefId ,
@@ -522,13 +522,7 @@ fn construct_fn<'tcx>(
522522 let return_block =
523523 unpack!( builder. in_breakable_scope( None , Place :: return_place( ) , fn_end, |builder| {
524524 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] )
532526 } ) )
533527 } ) ) ;
534528 let source_info = builder. source_info( fn_end) ;
@@ -704,9 +698,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
704698 thir,
705699 tcx,
706700 infcx,
707- typeck_results : tcx. typeck_opt_const_arg ( def) ,
708701 region_scope_tree : tcx. region_scope_tree ( def. did ) ,
709702 param_env,
703+ def,
710704 def_id : def. did . to_def_id ( ) ,
711705 hir_id,
712706 parent_module : tcx. parent_module ( hir_id) . to_def_id ( ) ,
@@ -756,14 +750,78 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
756750 self . var_debug_info ,
757751 self . fn_span ,
758752 self . generator_kind ,
759- self . typeck_results . tainted_by_errors ,
753+ None ,
760754 )
761755 }
762756
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+
763822 fn args_and_body (
764823 & mut self ,
765824 mut block : BasicBlock ,
766- fn_def_id : LocalDefId ,
767825 arguments : & IndexVec < ParamId , Param < ' tcx > > ,
768826 argument_scope : region:: Scope ,
769827 expr : & Expr < ' tcx > ,
@@ -785,69 +843,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
785843 }
786844 }
787845
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 ( ) ;
851847
852848 let mut scope = None ;
853849 // Bind the argument patterns
0 commit comments