@@ -12,7 +12,6 @@ use rustc_data_structures::graph;
1212use cfg:: * ;
1313use middle:: region:: CodeExtent ;
1414use ty:: { self , TyCtxt } ;
15- use syntax:: ast;
1615use syntax:: ptr:: P ;
1716
1817use hir:: { self , PatKind } ;
@@ -30,13 +29,13 @@ struct CFGBuilder<'a, 'tcx: 'a> {
3029
3130#[ derive( Copy , Clone ) ]
3231struct BlockScope {
33- block_expr_id : ast :: NodeId , // id of breakable block expr node
32+ block_expr_id : hir :: ItemLocalId , // id of breakable block expr node
3433 break_index : CFGIndex , // where to go on `break`
3534}
3635
3736#[ derive( Copy , Clone ) ]
3837struct LoopScope {
39- loop_id : ast :: NodeId , // id of loop/while node
38+ loop_id : hir :: ItemLocalId , // id of loop/while node
4039 continue_index : CFGIndex , // where to go on a `loop`
4140 break_index : CFGIndex , // where to go on a `break`
4241}
@@ -70,6 +69,7 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
7069 cfg_builder. add_contained_edge ( body_exit, fn_exit) ;
7170 let CFGBuilder { graph, .. } = cfg_builder;
7271 CFG {
72+ owner_def_id,
7373 graph,
7474 entry,
7575 exit : fn_exit,
@@ -79,10 +79,10 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
7979impl < ' a , ' tcx > CFGBuilder < ' a , ' tcx > {
8080 fn block ( & mut self , blk : & hir:: Block , pred : CFGIndex ) -> CFGIndex {
8181 if blk. targeted_by_break {
82- let expr_exit = self . add_ast_node ( blk. id , & [ ] ) ;
82+ let expr_exit = self . add_ast_node ( blk. hir_id . local_id , & [ ] ) ;
8383
8484 self . breakable_block_scopes . push ( BlockScope {
85- block_expr_id : blk. id ,
85+ block_expr_id : blk. hir_id . local_id ,
8686 break_index : expr_exit,
8787 } ) ;
8888
@@ -104,21 +104,22 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
104104
105105 let expr_exit = self . opt_expr ( & blk. expr , stmts_exit) ;
106106
107- self . add_ast_node ( blk. id , & [ expr_exit] )
107+ self . add_ast_node ( blk. hir_id . local_id , & [ expr_exit] )
108108 }
109109 }
110110
111111 fn stmt ( & mut self , stmt : & hir:: Stmt , pred : CFGIndex ) -> CFGIndex {
112+ let hir_id = self . tcx . hir . node_to_hir_id ( stmt. node . id ( ) ) ;
112113 match stmt. node {
113- hir:: StmtDecl ( ref decl, id ) => {
114+ hir:: StmtDecl ( ref decl, _ ) => {
114115 let exit = self . decl ( & decl, pred) ;
115- self . add_ast_node ( id , & [ exit] )
116+ self . add_ast_node ( hir_id . local_id , & [ exit] )
116117 }
117118
118- hir:: StmtExpr ( ref expr, id ) |
119- hir:: StmtSemi ( ref expr, id ) => {
119+ hir:: StmtExpr ( ref expr, _ ) |
120+ hir:: StmtSemi ( ref expr, _ ) => {
120121 let exit = self . expr ( & expr, pred) ;
121- self . add_ast_node ( id , & [ exit] )
122+ self . add_ast_node ( hir_id . local_id , & [ exit] )
122123 }
123124 }
124125 }
@@ -140,31 +141,31 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
140141 PatKind :: Path ( _) |
141142 PatKind :: Lit ( ..) |
142143 PatKind :: Range ( ..) |
143- PatKind :: Wild => self . add_ast_node ( pat. id , & [ pred] ) ,
144+ PatKind :: Wild => self . add_ast_node ( pat. hir_id . local_id , & [ pred] ) ,
144145
145146 PatKind :: Box ( ref subpat) |
146147 PatKind :: Ref ( ref subpat, _) |
147148 PatKind :: Binding ( .., Some ( ref subpat) ) => {
148149 let subpat_exit = self . pat ( & subpat, pred) ;
149- self . add_ast_node ( pat. id , & [ subpat_exit] )
150+ self . add_ast_node ( pat. hir_id . local_id , & [ subpat_exit] )
150151 }
151152
152153 PatKind :: TupleStruct ( _, ref subpats, _) |
153154 PatKind :: Tuple ( ref subpats, _) => {
154155 let pats_exit = self . pats_all ( subpats. iter ( ) , pred) ;
155- self . add_ast_node ( pat. id , & [ pats_exit] )
156+ self . add_ast_node ( pat. hir_id . local_id , & [ pats_exit] )
156157 }
157158
158159 PatKind :: Struct ( _, ref subpats, _) => {
159160 let pats_exit = self . pats_all ( subpats. iter ( ) . map ( |f| & f. node . pat ) , pred) ;
160- self . add_ast_node ( pat. id , & [ pats_exit] )
161+ self . add_ast_node ( pat. hir_id . local_id , & [ pats_exit] )
161162 }
162163
163164 PatKind :: Slice ( ref pre, ref vec, ref post) => {
164165 let pre_exit = self . pats_all ( pre. iter ( ) , pred) ;
165166 let vec_exit = self . pats_all ( vec. iter ( ) , pre_exit) ;
166167 let post_exit = self . pats_all ( post. iter ( ) , vec_exit) ;
167- self . add_ast_node ( pat. id , & [ post_exit] )
168+ self . add_ast_node ( pat. hir_id . local_id , & [ post_exit] )
168169 }
169170 }
170171 }
@@ -180,7 +181,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
180181 match expr. node {
181182 hir:: ExprBlock ( ref blk) => {
182183 let blk_exit = self . block ( & blk, pred) ;
183- self . add_ast_node ( expr. id , & [ blk_exit] )
184+ self . add_ast_node ( expr. hir_id . local_id , & [ blk_exit] )
184185 }
185186
186187 hir:: ExprIf ( ref cond, ref then, None ) => {
@@ -200,7 +201,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
200201 //
201202 let cond_exit = self . expr ( & cond, pred) ; // 1
202203 let then_exit = self . expr ( & then, cond_exit) ; // 2
203- self . add_ast_node ( expr. id , & [ cond_exit, then_exit] ) // 3,4
204+ self . add_ast_node ( expr. hir_id . local_id , & [ cond_exit, then_exit] ) // 3,4
204205 }
205206
206207 hir:: ExprIf ( ref cond, ref then, Some ( ref otherwise) ) => {
@@ -221,7 +222,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
221222 let cond_exit = self . expr ( & cond, pred) ; // 1
222223 let then_exit = self . expr ( & then, cond_exit) ; // 2
223224 let else_exit = self . expr ( & otherwise, cond_exit) ; // 3
224- self . add_ast_node ( expr. id , & [ then_exit, else_exit] ) // 4, 5
225+ self . add_ast_node ( expr. hir_id . local_id , & [ then_exit, else_exit] ) // 4, 5
225226 }
226227
227228 hir:: ExprWhile ( ref cond, ref body, _) => {
@@ -245,12 +246,12 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
245246 let loopback = self . add_dummy_node ( & [ pred] ) ; // 1
246247
247248 // Create expr_exit without pred (cond_exit)
248- let expr_exit = self . add_ast_node ( expr. id , & [ ] ) ; // 3
249+ let expr_exit = self . add_ast_node ( expr. hir_id . local_id , & [ ] ) ; // 3
249250
250251 // The LoopScope needs to be on the loop_scopes stack while evaluating the
251252 // condition and the body of the loop (both can break out of the loop)
252253 self . loop_scopes . push ( LoopScope {
253- loop_id : expr. id ,
254+ loop_id : expr. hir_id . local_id ,
254255 continue_index : loopback,
255256 break_index : expr_exit
256257 } ) ;
@@ -282,9 +283,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
282283 // may cause additional edges.
283284
284285 let loopback = self . add_dummy_node ( & [ pred] ) ; // 1
285- let expr_exit = self . add_ast_node ( expr. id , & [ ] ) ; // 2
286+ let expr_exit = self . add_ast_node ( expr. hir_id . local_id , & [ ] ) ; // 2
286287 self . loop_scopes . push ( LoopScope {
287- loop_id : expr. id ,
288+ loop_id : expr. hir_id . local_id ,
288289 continue_index : loopback,
289290 break_index : expr_exit,
290291 } ) ;
@@ -295,7 +296,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
295296 }
296297
297298 hir:: ExprMatch ( ref discr, ref arms, _) => {
298- self . match_ ( expr. id , & discr, & arms, pred)
299+ self . match_ ( expr. hir_id . local_id , & discr, & arms, pred)
299300 }
300301
301302 hir:: ExprBinary ( op, ref l, ref r) if op. node . is_lazy ( ) => {
@@ -315,30 +316,30 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
315316 //
316317 let l_exit = self . expr ( & l, pred) ; // 1
317318 let r_exit = self . expr ( & r, l_exit) ; // 2
318- self . add_ast_node ( expr. id , & [ l_exit, r_exit] ) // 3,4
319+ self . add_ast_node ( expr. hir_id . local_id , & [ l_exit, r_exit] ) // 3,4
319320 }
320321
321322 hir:: ExprRet ( ref v) => {
322323 let v_exit = self . opt_expr ( v, pred) ;
323- let b = self . add_ast_node ( expr. id , & [ v_exit] ) ;
324+ let b = self . add_ast_node ( expr. hir_id . local_id , & [ v_exit] ) ;
324325 self . add_returning_edge ( expr, b) ;
325326 self . add_unreachable_node ( )
326327 }
327328
328329 hir:: ExprBreak ( destination, ref opt_expr) => {
329330 let v = self . opt_expr ( opt_expr, pred) ;
330- let ( scope_id , break_dest) =
331+ let ( target_scope , break_dest) =
331332 self . find_scope_edge ( expr, destination, ScopeCfKind :: Break ) ;
332- let b = self . add_ast_node ( expr. id , & [ v] ) ;
333- self . add_exiting_edge ( expr, b, scope_id , break_dest) ;
333+ let b = self . add_ast_node ( expr. hir_id . local_id , & [ v] ) ;
334+ self . add_exiting_edge ( expr, b, target_scope , break_dest) ;
334335 self . add_unreachable_node ( )
335336 }
336337
337338 hir:: ExprAgain ( destination) => {
338- let ( scope_id , cont_dest) =
339+ let ( target_scope , cont_dest) =
339340 self . find_scope_edge ( expr, destination, ScopeCfKind :: Continue ) ;
340- let a = self . add_ast_node ( expr. id , & [ pred] ) ;
341- self . add_exiting_edge ( expr, a, scope_id , cont_dest) ;
341+ let a = self . add_ast_node ( expr. hir_id . local_id , & [ pred] ) ;
342+ self . add_exiting_edge ( expr, a, target_scope , cont_dest) ;
342343 self . add_unreachable_node ( )
343344 }
344345
@@ -397,7 +398,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
397398 hir:: ExprInlineAsm ( _, ref outputs, ref inputs) => {
398399 let post_outputs = self . exprs ( outputs. iter ( ) . map ( |e| & * e) , pred) ;
399400 let post_inputs = self . exprs ( inputs. iter ( ) . map ( |e| & * e) , post_outputs) ;
400- self . add_ast_node ( expr. id , & [ post_inputs] )
401+ self . add_ast_node ( expr. hir_id . local_id , & [ post_inputs] )
401402 }
402403
403404 hir:: ExprClosure ( ..) |
@@ -444,10 +445,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
444445 //! Handles case of an expression that evaluates `subexprs` in order
445446
446447 let subexprs_exit = self . exprs ( subexprs, pred) ;
447- self . add_ast_node ( expr. id , & [ subexprs_exit] )
448+ self . add_ast_node ( expr. hir_id . local_id , & [ subexprs_exit] )
448449 }
449450
450- fn match_ ( & mut self , id : ast :: NodeId , discr : & hir:: Expr ,
451+ fn match_ ( & mut self , id : hir :: ItemLocalId , discr : & hir:: Expr ,
451452 arms : & [ hir:: Arm ] , pred : CFGIndex ) -> CFGIndex {
452453 // The CFG for match expression is quite complex, so no ASCII
453454 // art for it (yet).
@@ -552,8 +553,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
552553 self . add_node ( CFGNodeData :: Dummy , preds)
553554 }
554555
555- fn add_ast_node ( & mut self , id : ast:: NodeId , preds : & [ CFGIndex ] ) -> CFGIndex {
556- assert ! ( id != ast:: DUMMY_NODE_ID ) ;
556+ fn add_ast_node ( & mut self , id : hir:: ItemLocalId , preds : & [ CFGIndex ] ) -> CFGIndex {
557557 self . add_node ( CFGNodeData :: AST ( id) , preds)
558558 }
559559
@@ -579,14 +579,13 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
579579 fn add_exiting_edge ( & mut self ,
580580 from_expr : & hir:: Expr ,
581581 from_index : CFGIndex ,
582- scope_id : ast :: NodeId ,
582+ target_scope : CodeExtent ,
583583 to_index : CFGIndex ) {
584584 let mut data = CFGEdgeData { exiting_scopes : vec ! [ ] } ;
585585 let mut scope = CodeExtent :: Misc ( from_expr. id ) ;
586- let target_scope = CodeExtent :: Misc ( scope_id) ;
587586 let region_maps = self . tcx . region_maps ( self . owner_def_id ) ;
588587 while scope != target_scope {
589- data. exiting_scopes . push ( scope. node_id ( ) ) ;
588+ data. exiting_scopes . push ( self . tcx . hir . node_to_hir_id ( scope. node_id ( ) ) . local_id ) ;
590589 scope = region_maps. encl_scope ( scope) ;
591590 }
592591 self . graph . add_edge ( from_index, to_index, data) ;
@@ -607,13 +606,13 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
607606 fn find_scope_edge ( & self ,
608607 expr : & hir:: Expr ,
609608 destination : hir:: Destination ,
610- scope_cf_kind : ScopeCfKind ) -> ( ast :: NodeId , CFGIndex ) {
609+ scope_cf_kind : ScopeCfKind ) -> ( CodeExtent , CFGIndex ) {
611610
612611 match destination. target_id {
613612 hir:: ScopeTarget :: Block ( block_expr_id) => {
614613 for b in & self . breakable_block_scopes {
615- if b. block_expr_id == block_expr_id {
616- return ( block_expr_id, match scope_cf_kind {
614+ if b. block_expr_id == self . tcx . hir . node_to_hir_id ( block_expr_id) . local_id {
615+ return ( CodeExtent :: Misc ( block_expr_id) , match scope_cf_kind {
617616 ScopeCfKind :: Break => b. break_index ,
618617 ScopeCfKind :: Continue => bug ! ( "can't continue to block" ) ,
619618 } ) ;
@@ -623,8 +622,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
623622 }
624623 hir:: ScopeTarget :: Loop ( hir:: LoopIdResult :: Ok ( loop_id) ) => {
625624 for l in & self . loop_scopes {
626- if l. loop_id == loop_id {
627- return ( loop_id, match scope_cf_kind {
625+ if l. loop_id == self . tcx . hir . node_to_hir_id ( loop_id) . local_id {
626+ return ( CodeExtent :: Misc ( loop_id) , match scope_cf_kind {
628627 ScopeCfKind :: Break => l. break_index ,
629628 ScopeCfKind :: Continue => l. continue_index ,
630629 } ) ;
0 commit comments