@@ -486,7 +486,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
486
486
// check for never_loop
487
487
match expr. node {
488
488
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) {
490
491
NeverLoopResult :: AlwaysBreak => {
491
492
span_lint ( cx, NEVER_LOOP , expr. span , "this loop never actually loops" )
492
493
} ,
@@ -1109,8 +1110,8 @@ fn check_for_loop_range<'a, 'tcx>(
1109
1110
1110
1111
// ensure that the indexed variable was declared before the loop, see #601
1111
1112
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) ;
1114
1115
let region_scope_tree = cx. tcx . region_scope_tree ( parent_def_id) ;
1115
1116
let pat_extent = region_scope_tree. var_scope ( pat. hir_id . local_id ) ;
1116
1117
if region_scope_tree. is_subscope_of ( indexed_extent, pat_extent) {
@@ -1469,8 +1470,9 @@ fn check_for_loop_explicit_counter<'a, 'tcx>(
1469
1470
// For each candidate, check the parent block to see if
1470
1471
// it's initialized to zero at the start of the loop.
1471
1472
let map = & cx. tcx . hir ( ) ;
1473
+ let expr_node_id = map. hir_to_node_id ( expr. hir_id ) ;
1472
1474
let parent_scope = map
1473
- . get_enclosing_scope ( expr . id )
1475
+ . get_enclosing_scope ( expr_node_id )
1474
1476
. and_then ( |id| map. get_enclosing_scope ( id) ) ;
1475
1477
if let Some ( parent_id) = parent_scope {
1476
1478
if let Node :: Block ( block) = map. get ( parent_id) {
@@ -1567,13 +1569,13 @@ struct MutatePairDelegate {
1567
1569
}
1568
1570
1569
1571
impl < ' 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 ) { }
1571
1573
1572
1574
fn matched_pat ( & mut self , _: & Pat , _: & cmt_ < ' tcx > , _: MatchMode ) { }
1573
1575
1574
1576
fn consume_pat ( & mut self , _: & Pat , _: & cmt_ < ' tcx > , _: ConsumeMode ) { }
1575
1577
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 ) {
1577
1579
if let ty:: BorrowKind :: MutBorrow = bk {
1578
1580
if let Categorization :: Local ( id) = cmt. cat {
1579
1581
if Some ( id) == self . node_id_low {
@@ -1586,7 +1588,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
1586
1588
}
1587
1589
}
1588
1590
1589
- fn mutate ( & mut self , _: NodeId , sp : Span , cmt : & cmt_ < ' tcx > , _: MutateMode ) {
1591
+ fn mutate ( & mut self , _: HirId , sp : Span , cmt : & cmt_ < ' tcx > , _: MutateMode ) {
1590
1592
if let Categorization :: Local ( id) = cmt. cat {
1591
1593
if Some ( id) == self . node_id_low {
1592
1594
self . span_low = Some ( sp)
@@ -1778,8 +1780,8 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
1778
1780
Def :: Local ( node_id) | Def :: Upvar ( node_id, ..) => {
1779
1781
let hir_id = self . cx. tcx. hir( ) . node_to_hir_id( node_id) ;
1780
1782
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) ;
1783
1785
let extent = self . cx. tcx. region_scope_tree( parent_def_id) . var_scope( hir_id. local_id) ;
1784
1786
if indexed_indirectly {
1785
1787
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
1932
1934
let mut visitor = VarUsedAfterLoopVisitor {
1933
1935
cx,
1934
1936
def_id,
1935
- iter_expr_id : iter_expr. id ,
1937
+ iter_expr_id : iter_expr. hir_id ,
1936
1938
past_while_let : false ,
1937
1939
var_used_after_while_let : false ,
1938
1940
} ;
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) {
1940
1943
walk_block ( & mut visitor, enclosing_block) ;
1941
1944
}
1942
1945
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
1945
1948
struct VarUsedAfterLoopVisitor < ' a , ' tcx : ' a > {
1946
1949
cx : & ' a LateContext < ' a , ' tcx > ,
1947
1950
def_id : NodeId ,
1948
- iter_expr_id : NodeId ,
1951
+ iter_expr_id : HirId ,
1949
1952
past_while_let : bool ,
1950
1953
var_used_after_while_let : bool ,
1951
1954
}
@@ -1956,7 +1959,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> {
1956
1959
if Some ( self . def_id ) == var_def_id ( self . cx , expr) {
1957
1960
self . var_used_after_while_let = true ;
1958
1961
}
1959
- } else if self . iter_expr_id == expr. id {
1962
+ } else if self . iter_expr_id == expr. hir_id {
1960
1963
self . past_while_let = true ;
1961
1964
}
1962
1965
walk_expr ( self , expr) ;
@@ -2068,7 +2071,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
2068
2071
2069
2072
match parent. node {
2070
2073
ExprKind :: AssignOp ( op, ref lhs, ref rhs) => {
2071
- if lhs. id == expr. id {
2074
+ if lhs. hir_id == expr. hir_id {
2072
2075
if op. node == BinOpKind :: Add && is_integer_literal ( rhs, 1 ) {
2073
2076
* state = match * state {
2074
2077
VarState :: Initial if self . depth == 0 => VarState :: IncrOnce ,
@@ -2080,7 +2083,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
2080
2083
}
2081
2084
}
2082
2085
} ,
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 ,
2084
2087
ExprKind :: AddrOf ( mutability, _) if mutability == MutMutable => * state = VarState :: DontWarn ,
2085
2088
_ => ( ) ,
2086
2089
}
@@ -2153,10 +2156,10 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
2153
2156
if var_def_id ( self . cx , expr) == Some ( self . var_id ) {
2154
2157
if let Some ( parent) = get_parent_expr ( self . cx , expr) {
2155
2158
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 => {
2157
2160
self . state = VarState :: DontWarn ;
2158
2161
} ,
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 => {
2160
2163
self . state = if is_integer_literal ( rhs, 0 ) && self . depth == 0 {
2161
2164
VarState :: Warn
2162
2165
} else {
@@ -2214,8 +2217,9 @@ fn is_conditional(expr: &Expr) -> bool {
2214
2217
2215
2218
fn is_nested ( cx : & LateContext < ' _ , ' _ > , match_expr : & Expr , iter_expr : & Expr ) -> bool {
2216
2219
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
+ let parent_node = cx. tcx. hir( ) . get_parent_node_by_hir_id( loop_block. hir_id) ;
2222
+ if let Some ( Node :: Expr ( loop_expr) ) = cx. tcx. hir( ) . find_by_hir_id( parent_node) ;
2219
2223
then {
2220
2224
return is_loop_nested( cx, loop_expr, iter_expr)
2221
2225
}
@@ -2224,18 +2228,18 @@ fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> b
2224
2228
}
2225
2229
2226
2230
fn is_loop_nested ( cx : & LateContext < ' _ , ' _ > , loop_expr : & Expr , iter_expr : & Expr ) -> bool {
2227
- let mut id = loop_expr. id ;
2231
+ let mut id = loop_expr. hir_id ;
2228
2232
let iter_name = if let Some ( name) = path_name ( iter_expr) {
2229
2233
name
2230
2234
} else {
2231
2235
return true ;
2232
2236
} ;
2233
2237
loop {
2234
- let parent = cx. tcx . hir ( ) . get_parent_node ( id) ;
2238
+ let parent = cx. tcx . hir ( ) . get_parent_node_by_hir_id ( id) ;
2235
2239
if parent == id {
2236
2240
return false ;
2237
2241
}
2238
- match cx. tcx . hir ( ) . find ( parent) {
2242
+ match cx. tcx . hir ( ) . find_by_hir_id ( parent) {
2239
2243
Some ( Node :: Expr ( expr) ) => match expr. node {
2240
2244
ExprKind :: Loop ( ..) | ExprKind :: While ( ..) => {
2241
2245
return true ;
@@ -2244,7 +2248,7 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr)
2244
2248
} ,
2245
2249
Some ( Node :: Block ( block) ) => {
2246
2250
let mut block_visitor = LoopNestVisitor {
2247
- id,
2251
+ hir_id : id,
2248
2252
iterator : iter_name,
2249
2253
nesting : Unknown ,
2250
2254
} ;
@@ -2272,14 +2276,14 @@ enum Nesting {
2272
2276
use self :: Nesting :: { LookFurther , RuledOut , Unknown } ;
2273
2277
2274
2278
struct LoopNestVisitor {
2275
- id : NodeId ,
2279
+ hir_id : HirId ,
2276
2280
iterator : Name ,
2277
2281
nesting : Nesting ,
2278
2282
}
2279
2283
2280
2284
impl < ' tcx > Visitor < ' tcx > for LoopNestVisitor {
2281
2285
fn visit_stmt ( & mut self , stmt : & ' tcx Stmt ) {
2282
- if stmt. id == self . id {
2286
+ if stmt. hir_id == self . hir_id {
2283
2287
self . nesting = LookFurther ;
2284
2288
} else if self . nesting == Unknown {
2285
2289
walk_stmt ( self , stmt) ;
@@ -2290,7 +2294,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
2290
2294
if self . nesting != Unknown {
2291
2295
return ;
2292
2296
}
2293
- if expr. id == self . id {
2297
+ if expr. hir_id == self . hir_id {
2294
2298
self . nesting = LookFurther ;
2295
2299
return ;
2296
2300
}
0 commit comments