@@ -90,12 +90,12 @@ use rustc_errors::Applicability;
9090use rustc_hir as hir;
9191use rustc_hir:: def:: * ;
9292use rustc_hir:: def_id:: LocalDefId ;
93- use rustc_hir:: intravisit:: { self , FnKind , NestedVisitorMap , Visitor } ;
94- use rustc_hir:: { Expr , HirId , HirIdMap , HirIdSet , Node } ;
93+ use rustc_hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
94+ use rustc_hir:: { Expr , HirId , HirIdMap , HirIdSet } ;
9595use rustc_index:: vec:: IndexVec ;
9696use rustc_middle:: hir:: map:: Map ;
9797use rustc_middle:: ty:: query:: Providers ;
98- use rustc_middle:: ty:: { self , TyCtxt } ;
98+ use rustc_middle:: ty:: { self , DefIdTree , TyCtxt } ;
9999use rustc_session:: lint;
100100use rustc_span:: symbol:: { kw, sym, Symbol } ;
101101use rustc_span:: Span ;
@@ -318,49 +318,38 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
318318 NestedVisitorMap :: OnlyBodies ( self . tcx . hir ( ) )
319319 }
320320
321- fn visit_fn (
322- & mut self ,
323- fk : FnKind < ' tcx > ,
324- decl : & ' tcx hir:: FnDecl < ' tcx > ,
325- body_id : hir:: BodyId ,
326- sp : Span ,
327- id : HirId ,
328- ) {
329- debug ! ( "visit_fn {:?}" , id) ;
321+ fn visit_body ( & mut self , body : & ' tcx hir:: Body < ' tcx > ) {
322+ debug ! ( "visit_body {:?}" , body. id( ) ) ;
330323
331- // swap in a new set of IR maps for this function body:
332- let def_id = self . tcx . hir ( ) . local_def_id ( id) ;
333- let mut fn_maps = IrMaps :: new ( self . tcx ) ;
324+ // swap in a new set of IR maps for this body
325+ let mut maps = IrMaps :: new ( self . tcx ) ;
326+ let hir_id = maps. tcx . hir ( ) . body_owner ( body. id ( ) ) ;
327+ let def_id = maps. tcx . hir ( ) . local_def_id ( hir_id) ;
334328
335329 // Don't run unused pass for #[derive()]
336- if let FnKind :: Method ( ..) = fk {
337- let parent = self . tcx . hir ( ) . get_parent_item ( id) ;
338- if let Some ( Node :: Item ( i) ) = self . tcx . hir ( ) . find ( parent) {
339- if i. attrs . iter ( ) . any ( |a| self . tcx . sess . check_name ( a, sym:: automatically_derived) ) {
330+ if let Some ( parent) = self . tcx . parent ( def_id. to_def_id ( ) ) {
331+ if let DefKind :: Impl = self . tcx . def_kind ( parent. expect_local ( ) ) {
332+ if self . tcx . has_attr ( parent, sym:: automatically_derived) {
340333 return ;
341334 }
342335 }
343336 }
344337
345- debug ! ( "creating fn_maps: {:p}" , & fn_maps) ;
346-
347- let body = self . tcx . hir ( ) . body ( body_id) ;
348-
349- if let Some ( upvars) = self . tcx . upvars_mentioned ( def_id) {
338+ if let Some ( upvars) = maps. tcx . upvars_mentioned ( def_id) {
350339 for ( & var_hir_id, _upvar) in upvars {
351- let var_name = self . tcx . hir ( ) . name ( var_hir_id) ;
352- fn_maps . add_variable ( Upvar ( var_hir_id, var_name) ) ;
340+ let var_name = maps . tcx . hir ( ) . name ( var_hir_id) ;
341+ maps . add_variable ( Upvar ( var_hir_id, var_name) ) ;
353342 }
354343 }
355344
356345 // gather up the various local variables, significant expressions,
357346 // and so forth:
358- intravisit:: walk_fn ( & mut fn_maps , fk , decl , body_id , sp , id ) ;
347+ intravisit:: walk_body ( & mut maps , body ) ;
359348
360349 // compute liveness
361- let mut lsets = Liveness :: new ( & mut fn_maps , def_id) ;
362- let entry_ln = lsets. compute ( & body, sp , id ) ;
363- lsets. log_liveness ( entry_ln, id ) ;
350+ let mut lsets = Liveness :: new ( & mut maps , def_id) ;
351+ let entry_ln = lsets. compute ( & body, hir_id ) ;
352+ lsets. log_liveness ( entry_ln, body . id ( ) . hir_id ) ;
364353
365354 // check for various error conditions
366355 lsets. visit_body ( body) ;
@@ -845,8 +834,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
845834 self . rwu_table . assign_unpacked ( idx, rwu) ;
846835 }
847836
848- fn compute ( & mut self , body : & hir:: Body < ' _ > , span : Span , id : hir :: HirId ) -> LiveNode {
849- debug ! ( "compute: using id for body, {:?}" , body. value ) ;
837+ fn compute ( & mut self , body : & hir:: Body < ' _ > , hir_id : HirId ) -> LiveNode {
838+ debug ! ( "compute: for body {:?}" , body. id ( ) . hir_id ) ;
850839
851840 // # Liveness of captured variables
852841 //
@@ -890,7 +879,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
890879 return succ;
891880 }
892881
893- let ty = self . typeck_results . node_type ( id ) ;
882+ let ty = self . typeck_results . node_type ( hir_id ) ;
894883 match ty. kind ( ) {
895884 ty:: Closure ( _def_id, substs) => match substs. as_closure ( ) . kind ( ) {
896885 ty:: ClosureKind :: Fn => { }
@@ -899,7 +888,12 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
899888 } ,
900889 ty:: Generator ( ..) => return succ,
901890 _ => {
902- span_bug ! ( span, "{} has upvars so it should have a closure type: {:?}" , id, ty) ;
891+ span_bug ! (
892+ body. value. span,
893+ "{} has upvars so it should have a closure type: {:?}" ,
894+ hir_id,
895+ ty
896+ ) ;
903897 }
904898 } ;
905899
0 commit comments