@@ -90,12 +90,12 @@ use rustc_errors::Applicability;
90
90
use rustc_hir as hir;
91
91
use rustc_hir:: def:: * ;
92
92
use 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 } ;
95
95
use rustc_index:: vec:: IndexVec ;
96
96
use rustc_middle:: hir:: map:: Map ;
97
97
use rustc_middle:: ty:: query:: Providers ;
98
- use rustc_middle:: ty:: { self , TyCtxt } ;
98
+ use rustc_middle:: ty:: { self , DefIdTree , TyCtxt } ;
99
99
use rustc_session:: lint;
100
100
use rustc_span:: symbol:: { kw, sym, Symbol } ;
101
101
use rustc_span:: Span ;
@@ -318,49 +318,38 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
318
318
NestedVisitorMap :: OnlyBodies ( self . tcx . hir ( ) )
319
319
}
320
320
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( ) ) ;
330
323
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) ;
334
328
335
329
// 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) {
340
333
return ;
341
334
}
342
335
}
343
336
}
344
337
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) {
350
339
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) ) ;
353
342
}
354
343
}
355
344
356
345
// gather up the various local variables, significant expressions,
357
346
// and so forth:
358
- intravisit:: walk_fn ( & mut fn_maps , fk , decl , body_id , sp , id ) ;
347
+ intravisit:: walk_body ( & mut maps , body ) ;
359
348
360
349
// 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 ) ;
364
353
365
354
// check for various error conditions
366
355
lsets. visit_body ( body) ;
@@ -845,8 +834,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
845
834
self . rwu_table . assign_unpacked ( idx, rwu) ;
846
835
}
847
836
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 ) ;
850
839
851
840
// # Liveness of captured variables
852
841
//
@@ -890,7 +879,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
890
879
return succ;
891
880
}
892
881
893
- let ty = self . typeck_results . node_type ( id ) ;
882
+ let ty = self . typeck_results . node_type ( hir_id ) ;
894
883
match ty. kind ( ) {
895
884
ty:: Closure ( _def_id, substs) => match substs. as_closure ( ) . kind ( ) {
896
885
ty:: ClosureKind :: Fn => { }
@@ -899,7 +888,12 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
899
888
} ,
900
889
ty:: Generator ( ..) => return succ,
901
890
_ => {
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
+ ) ;
903
897
}
904
898
} ;
905
899
0 commit comments