@@ -486,7 +486,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
486486 // check for never_loop
487487 match expr. node {
488488 ExprKind :: While ( _, ref block, _) | ExprKind :: Loop ( ref block, _, _) => {
489- match never_loop_block ( block, expr. id ) {
489+ let node_id = cx. tcx . hir ( ) . hir_to_node_id ( expr. hir_id ) ;
490+ match never_loop_block ( block, node_id) {
490491 NeverLoopResult :: AlwaysBreak => {
491492 span_lint ( cx, NEVER_LOOP , expr. span , "this loop never actually loops" )
492493 } ,
@@ -1109,8 +1110,8 @@ fn check_for_loop_range<'a, 'tcx>(
11091110
11101111 // ensure that the indexed variable was declared before the loop, see #601
11111112 if let Some ( indexed_extent) = indexed_extent {
1112- let parent_id = cx. tcx . hir ( ) . get_parent ( expr. id ) ;
1113- let parent_def_id = cx. tcx . hir ( ) . local_def_id ( parent_id) ;
1113+ let parent_id = cx. tcx . hir ( ) . get_parent_item ( expr. hir_id ) ;
1114+ let parent_def_id = cx. tcx . hir ( ) . local_def_id_from_hir_id ( parent_id) ;
11141115 let region_scope_tree = cx. tcx . region_scope_tree ( parent_def_id) ;
11151116 let pat_extent = region_scope_tree. var_scope ( pat. hir_id . local_id ) ;
11161117 if region_scope_tree. is_subscope_of ( indexed_extent, pat_extent) {
@@ -1469,8 +1470,9 @@ fn check_for_loop_explicit_counter<'a, 'tcx>(
14691470 // For each candidate, check the parent block to see if
14701471 // it's initialized to zero at the start of the loop.
14711472 let map = & cx. tcx . hir ( ) ;
1473+ let expr_node_id = map. hir_to_node_id ( expr. hir_id ) ;
14721474 let parent_scope = map
1473- . get_enclosing_scope ( expr . id )
1475+ . get_enclosing_scope ( expr_node_id )
14741476 . and_then ( |id| map. get_enclosing_scope ( id) ) ;
14751477 if let Some ( parent_id) = parent_scope {
14761478 if let Node :: Block ( block) = map. get ( parent_id) {
@@ -1567,13 +1569,13 @@ struct MutatePairDelegate {
15671569}
15681570
15691571impl < ' tcx > Delegate < ' tcx > for MutatePairDelegate {
1570- fn consume ( & mut self , _: NodeId , _: Span , _: & cmt_ < ' tcx > , _: ConsumeMode ) { }
1572+ fn consume ( & mut self , _: HirId , _: Span , _: & cmt_ < ' tcx > , _: ConsumeMode ) { }
15711573
15721574 fn matched_pat ( & mut self , _: & Pat , _: & cmt_ < ' tcx > , _: MatchMode ) { }
15731575
15741576 fn consume_pat ( & mut self , _: & Pat , _: & cmt_ < ' tcx > , _: ConsumeMode ) { }
15751577
1576- fn borrow ( & mut self , _: NodeId , sp : Span , cmt : & cmt_ < ' tcx > , _: ty:: Region < ' _ > , bk : ty:: BorrowKind , _: LoanCause ) {
1578+ fn borrow ( & mut self , _: HirId , sp : Span , cmt : & cmt_ < ' tcx > , _: ty:: Region < ' _ > , bk : ty:: BorrowKind , _: LoanCause ) {
15771579 if let ty:: BorrowKind :: MutBorrow = bk {
15781580 if let Categorization :: Local ( id) = cmt. cat {
15791581 if Some ( id) == self . node_id_low {
@@ -1586,7 +1588,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
15861588 }
15871589 }
15881590
1589- fn mutate ( & mut self , _: NodeId , sp : Span , cmt : & cmt_ < ' tcx > , _: MutateMode ) {
1591+ fn mutate ( & mut self , _: HirId , sp : Span , cmt : & cmt_ < ' tcx > , _: MutateMode ) {
15901592 if let Categorization :: Local ( id) = cmt. cat {
15911593 if Some ( id) == self . node_id_low {
15921594 self . span_low = Some ( sp)
@@ -1778,8 +1780,8 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
17781780 Def :: Local ( node_id) | Def :: Upvar ( node_id, ..) => {
17791781 let hir_id = self . cx. tcx. hir( ) . node_to_hir_id( node_id) ;
17801782
1781- let parent_id = self . cx. tcx. hir( ) . get_parent ( expr. id ) ;
1782- let parent_def_id = self . cx. tcx. hir( ) . local_def_id ( parent_id) ;
1783+ let parent_id = self . cx. tcx. hir( ) . get_parent_item ( expr. hir_id ) ;
1784+ let parent_def_id = self . cx. tcx. hir( ) . local_def_id_from_hir_id ( parent_id) ;
17831785 let extent = self . cx. tcx. region_scope_tree( parent_def_id) . var_scope( hir_id. local_id) ;
17841786 if indexed_indirectly {
17851787 self . indexed_indirectly. insert( seqvar. segments[ 0 ] . ident. name, Some ( extent) ) ;
@@ -1932,11 +1934,12 @@ fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, it
19321934 let mut visitor = VarUsedAfterLoopVisitor {
19331935 cx,
19341936 def_id,
1935- iter_expr_id : iter_expr. id ,
1937+ iter_expr_id : iter_expr. hir_id ,
19361938 past_while_let : false ,
19371939 var_used_after_while_let : false ,
19381940 } ;
1939- if let Some ( enclosing_block) = get_enclosing_block ( cx, def_id) {
1941+ let def_hir_id = cx. tcx . hir ( ) . node_to_hir_id ( def_id) ;
1942+ if let Some ( enclosing_block) = get_enclosing_block ( cx, def_hir_id) {
19401943 walk_block ( & mut visitor, enclosing_block) ;
19411944 }
19421945 visitor. var_used_after_while_let
@@ -1945,7 +1948,7 @@ fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, it
19451948struct VarUsedAfterLoopVisitor < ' a , ' tcx : ' a > {
19461949 cx : & ' a LateContext < ' a , ' tcx > ,
19471950 def_id : NodeId ,
1948- iter_expr_id : NodeId ,
1951+ iter_expr_id : HirId ,
19491952 past_while_let : bool ,
19501953 var_used_after_while_let : bool ,
19511954}
@@ -1956,7 +1959,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> {
19561959 if Some ( self . def_id ) == var_def_id ( self . cx , expr) {
19571960 self . var_used_after_while_let = true ;
19581961 }
1959- } else if self . iter_expr_id == expr. id {
1962+ } else if self . iter_expr_id == expr. hir_id {
19601963 self . past_while_let = true ;
19611964 }
19621965 walk_expr ( self , expr) ;
@@ -2068,7 +2071,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
20682071
20692072 match parent. node {
20702073 ExprKind :: AssignOp ( op, ref lhs, ref rhs) => {
2071- if lhs. id == expr. id {
2074+ if lhs. hir_id == expr. hir_id {
20722075 if op. node == BinOpKind :: Add && is_integer_literal ( rhs, 1 ) {
20732076 * state = match * state {
20742077 VarState :: Initial if self . depth == 0 => VarState :: IncrOnce ,
@@ -2080,7 +2083,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
20802083 }
20812084 }
20822085 } ,
2083- ExprKind :: Assign ( ref lhs, _) if lhs. id == expr. id => * state = VarState :: DontWarn ,
2086+ ExprKind :: Assign ( ref lhs, _) if lhs. hir_id == expr. hir_id => * state = VarState :: DontWarn ,
20842087 ExprKind :: AddrOf ( mutability, _) if mutability == MutMutable => * state = VarState :: DontWarn ,
20852088 _ => ( ) ,
20862089 }
@@ -2153,10 +2156,10 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
21532156 if var_def_id ( self . cx , expr) == Some ( self . var_id ) {
21542157 if let Some ( parent) = get_parent_expr ( self . cx , expr) {
21552158 match parent. node {
2156- ExprKind :: AssignOp ( _, ref lhs, _) if lhs. id == expr. id => {
2159+ ExprKind :: AssignOp ( _, ref lhs, _) if lhs. hir_id == expr. hir_id => {
21572160 self . state = VarState :: DontWarn ;
21582161 } ,
2159- ExprKind :: Assign ( ref lhs, ref rhs) if lhs. id == expr. id => {
2162+ ExprKind :: Assign ( ref lhs, ref rhs) if lhs. hir_id == expr. hir_id => {
21602163 self . state = if is_integer_literal ( rhs, 0 ) && self . depth == 0 {
21612164 VarState :: Warn
21622165 } else {
@@ -2214,8 +2217,8 @@ fn is_conditional(expr: &Expr) -> bool {
22142217
22152218fn is_nested ( cx : & LateContext < ' _ , ' _ > , match_expr : & Expr , iter_expr : & Expr ) -> bool {
22162219 if_chain ! {
2217- if let Some ( loop_block) = get_enclosing_block( cx, match_expr. id ) ;
2218- if let Some ( Node :: Expr ( loop_expr) ) = cx. tcx. hir( ) . find ( cx. tcx. hir( ) . get_parent_node ( loop_block. id ) ) ;
2220+ if let Some ( loop_block) = get_enclosing_block( cx, match_expr. hir_id ) ;
2221+ if let Some ( Node :: Expr ( loop_expr) ) = cx. tcx. hir( ) . find_by_hir_id ( cx. tcx. hir( ) . get_parent_node_by_hir_id ( loop_block. hir_id ) ) ;
22192222 then {
22202223 return is_loop_nested( cx, loop_expr, iter_expr)
22212224 }
@@ -2224,18 +2227,18 @@ fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> b
22242227}
22252228
22262229fn is_loop_nested ( cx : & LateContext < ' _ , ' _ > , loop_expr : & Expr , iter_expr : & Expr ) -> bool {
2227- let mut id = loop_expr. id ;
2230+ let mut id = loop_expr. hir_id ;
22282231 let iter_name = if let Some ( name) = path_name ( iter_expr) {
22292232 name
22302233 } else {
22312234 return true ;
22322235 } ;
22332236 loop {
2234- let parent = cx. tcx . hir ( ) . get_parent_node ( id) ;
2237+ let parent = cx. tcx . hir ( ) . get_parent_node_by_hir_id ( id) ;
22352238 if parent == id {
22362239 return false ;
22372240 }
2238- match cx. tcx . hir ( ) . find ( parent) {
2241+ match cx. tcx . hir ( ) . find_by_hir_id ( parent) {
22392242 Some ( Node :: Expr ( expr) ) => match expr. node {
22402243 ExprKind :: Loop ( ..) | ExprKind :: While ( ..) => {
22412244 return true ;
@@ -2244,7 +2247,7 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr)
22442247 } ,
22452248 Some ( Node :: Block ( block) ) => {
22462249 let mut block_visitor = LoopNestVisitor {
2247- id,
2250+ hir_id : id,
22482251 iterator : iter_name,
22492252 nesting : Unknown ,
22502253 } ;
@@ -2272,14 +2275,14 @@ enum Nesting {
22722275use self :: Nesting :: { LookFurther , RuledOut , Unknown } ;
22732276
22742277struct LoopNestVisitor {
2275- id : NodeId ,
2278+ hir_id : HirId ,
22762279 iterator : Name ,
22772280 nesting : Nesting ,
22782281}
22792282
22802283impl < ' tcx > Visitor < ' tcx > for LoopNestVisitor {
22812284 fn visit_stmt ( & mut self , stmt : & ' tcx Stmt ) {
2282- if stmt. id == self . id {
2285+ if stmt. hir_id == self . hir_id {
22832286 self . nesting = LookFurther ;
22842287 } else if self . nesting == Unknown {
22852288 walk_stmt ( self , stmt) ;
@@ -2290,7 +2293,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
22902293 if self . nesting != Unknown {
22912294 return ;
22922295 }
2293- if expr. id == self . id {
2296+ if expr. hir_id == self . hir_id {
22942297 self . nesting = LookFurther ;
22952298 return ;
22962299 }
0 commit comments