@@ -486,8 +486,7 @@ 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
- let node_id = cx. tcx . hir ( ) . hir_to_node_id ( expr. hir_id ) ;
490
- match never_loop_block ( block, node_id) {
489
+ match never_loop_block ( block, expr. hir_id ) {
491
490
NeverLoopResult :: AlwaysBreak => {
492
491
span_lint ( cx, NEVER_LOOP , expr. span , "this loop never actually loops" )
493
492
} ,
@@ -664,7 +663,7 @@ fn combine_branches(b1: NeverLoopResult, b2: NeverLoopResult) -> NeverLoopResult
664
663
}
665
664
}
666
665
667
- fn never_loop_block ( block : & Block , main_loop_id : NodeId ) -> NeverLoopResult {
666
+ fn never_loop_block ( block : & Block , main_loop_id : HirId ) -> NeverLoopResult {
668
667
let stmts = block. stmts . iter ( ) . map ( stmt_to_expr) ;
669
668
let expr = once ( block. expr . as_ref ( ) . map ( |p| & * * p) ) ;
670
669
let mut iter = stmts. chain ( expr) . filter_map ( |e| e) ;
@@ -679,7 +678,7 @@ fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> {
679
678
}
680
679
}
681
680
682
- fn never_loop_expr ( expr : & Expr , main_loop_id : NodeId ) -> NeverLoopResult {
681
+ fn never_loop_expr ( expr : & Expr , main_loop_id : HirId ) -> NeverLoopResult {
683
682
match expr. node {
684
683
ExprKind :: Box ( ref e)
685
684
| ExprKind :: Unary ( _, ref e)
@@ -753,17 +752,17 @@ fn never_loop_expr(expr: &Expr, main_loop_id: NodeId) -> NeverLoopResult {
753
752
}
754
753
}
755
754
756
- fn never_loop_expr_seq < ' a , T : Iterator < Item = & ' a Expr > > ( es : & mut T , main_loop_id : NodeId ) -> NeverLoopResult {
755
+ fn never_loop_expr_seq < ' a , T : Iterator < Item = & ' a Expr > > ( es : & mut T , main_loop_id : HirId ) -> NeverLoopResult {
757
756
es. map ( |e| never_loop_expr ( e, main_loop_id) )
758
757
. fold ( NeverLoopResult :: Otherwise , combine_seq)
759
758
}
760
759
761
- fn never_loop_expr_all < ' a , T : Iterator < Item = & ' a Expr > > ( es : & mut T , main_loop_id : NodeId ) -> NeverLoopResult {
760
+ fn never_loop_expr_all < ' a , T : Iterator < Item = & ' a Expr > > ( es : & mut T , main_loop_id : HirId ) -> NeverLoopResult {
762
761
es. map ( |e| never_loop_expr ( e, main_loop_id) )
763
762
. fold ( NeverLoopResult :: Otherwise , combine_both)
764
763
}
765
764
766
- fn never_loop_expr_branch < ' a , T : Iterator < Item = & ' a Expr > > ( e : & mut T , main_loop_id : NodeId ) -> NeverLoopResult {
765
+ fn never_loop_expr_branch < ' a , T : Iterator < Item = & ' a Expr > > ( e : & mut T , main_loop_id : HirId ) -> NeverLoopResult {
767
766
e. map ( |e| never_loop_expr ( e, main_loop_id) )
768
767
. fold ( NeverLoopResult :: AlwaysBreak , combine_branches)
769
768
}
@@ -784,14 +783,14 @@ fn check_for_loop<'a, 'tcx>(
784
783
detect_manual_memcpy ( cx, pat, arg, body, expr) ;
785
784
}
786
785
787
- fn same_var < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , expr : & Expr , var : ast :: NodeId ) -> bool {
786
+ fn same_var < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , expr : & Expr , var : HirId ) -> bool {
788
787
if_chain ! {
789
788
if let ExprKind :: Path ( ref qpath) = expr. node;
790
789
if let QPath :: Resolved ( None , ref path) = * qpath;
791
790
if path. segments. len( ) == 1 ;
792
791
if let Def :: Local ( local_id) = cx. tables. qpath_def( qpath, expr. hir_id) ;
793
792
// our variable!
794
- if local_id == var;
793
+ if cx . tcx . hir ( ) . node_to_hir_id ( local_id) == var;
795
794
then {
796
795
return true ;
797
796
}
@@ -833,8 +832,8 @@ fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool {
833
832
is_slice || match_type ( cx, ty, & paths:: VEC ) || match_type ( cx, ty, & paths:: VEC_DEQUE )
834
833
}
835
834
836
- fn get_fixed_offset_var < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , expr : & Expr , var : ast :: NodeId ) -> Option < FixedOffsetVar > {
837
- fn extract_offset < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , e : & Expr , var : ast :: NodeId ) -> Option < String > {
835
+ fn get_fixed_offset_var < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , expr : & Expr , var : HirId ) -> Option < FixedOffsetVar > {
836
+ fn extract_offset < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , e : & Expr , var : HirId ) -> Option < String > {
838
837
match e. node {
839
838
ExprKind :: Lit ( ref l) => match l. node {
840
839
ast:: LitKind :: Int ( x, _ty) => Some ( x. to_string ( ) ) ,
@@ -889,7 +888,7 @@ fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var:
889
888
fn fetch_cloned_fixed_offset_var < ' a , ' tcx > (
890
889
cx : & LateContext < ' a , ' tcx > ,
891
890
expr : & Expr ,
892
- var : ast :: NodeId ,
891
+ var : HirId ,
893
892
) -> Option < FixedOffsetVar > {
894
893
if_chain ! {
895
894
if let ExprKind :: MethodCall ( ref method, _, ref args) = expr. node;
@@ -907,12 +906,12 @@ fn fetch_cloned_fixed_offset_var<'a, 'tcx>(
907
906
fn get_indexed_assignments < ' a , ' tcx > (
908
907
cx : & LateContext < ' a , ' tcx > ,
909
908
body : & Expr ,
910
- var : ast :: NodeId ,
909
+ var : HirId ,
911
910
) -> Vec < ( FixedOffsetVar , FixedOffsetVar ) > {
912
911
fn get_assignment < ' a , ' tcx > (
913
912
cx : & LateContext < ' a , ' tcx > ,
914
913
e : & Expr ,
915
- var : ast :: NodeId ,
914
+ var : HirId ,
916
915
) -> Option < ( FixedOffsetVar , FixedOffsetVar ) > {
917
916
if let ExprKind :: Assign ( ref lhs, ref rhs) = e. node {
918
917
match (
@@ -970,7 +969,7 @@ fn detect_manual_memcpy<'a, 'tcx>(
970
969
} ) = higher:: range ( cx, arg)
971
970
{
972
971
// the var must be a single name
973
- if let PatKind :: Binding ( _, canonical_id, _, _, _ ) = pat. node {
972
+ if let PatKind :: Binding ( _, canonical_id, _, _) = pat. node {
974
973
let print_sum = |arg1 : & Offset , arg2 : & Offset | -> String {
975
974
match ( & arg1. value [ ..] , arg1. negate , & arg2. value [ ..] , arg2. negate ) {
976
975
( "0" , _, "0" , _) => "" . into ( ) ,
@@ -1087,7 +1086,7 @@ fn check_for_loop_range<'a, 'tcx>(
1087
1086
} ) = higher:: range ( cx, arg)
1088
1087
{
1089
1088
// the var must be a single name
1090
- if let PatKind :: Binding ( _, canonical_id, _ , ident, _) = pat. node {
1089
+ if let PatKind :: Binding ( _, canonical_id, ident, _) = pat. node {
1091
1090
let mut visitor = VarVisitor {
1092
1091
cx,
1093
1092
var : canonical_id,
@@ -1711,7 +1710,7 @@ impl<'tcx> Visitor<'tcx> for UsedVisitor {
1711
1710
1712
1711
struct LocalUsedVisitor < ' a , ' tcx : ' a > {
1713
1712
cx : & ' a LateContext < ' a , ' tcx > ,
1714
- local : ast :: NodeId ,
1713
+ local : HirId ,
1715
1714
used : bool ,
1716
1715
}
1717
1716
@@ -1733,7 +1732,7 @@ struct VarVisitor<'a, 'tcx: 'a> {
1733
1732
/// context reference
1734
1733
cx : & ' a LateContext < ' a , ' tcx > ,
1735
1734
/// var name to look for as index
1736
- var : ast :: NodeId ,
1735
+ var : HirId ,
1737
1736
/// indexed variables that are used mutably
1738
1737
indexed_mut : FxHashSet < Name > ,
1739
1738
/// indirectly indexed variables (`v[(i + 4) % N]`), the extend is `None` for global
@@ -1841,15 +1840,15 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
1841
1840
then {
1842
1841
match self . cx. tables. qpath_def( qpath, expr. hir_id) {
1843
1842
Def :: Upvar ( local_id, ..) => {
1844
- if local_id == self . var {
1843
+ if self . cx . tcx . hir ( ) . node_to_hir_id ( local_id) == self . var {
1845
1844
// we are not indexing anything, record that
1846
1845
self . nonindex = true ;
1847
1846
}
1848
1847
}
1849
1848
Def :: Local ( local_id) =>
1850
1849
{
1851
1850
1852
- if local_id == self . var {
1851
+ if self . cx . tcx . hir ( ) . node_to_hir_id ( local_id) == self . var {
1853
1852
self . nonindex = true ;
1854
1853
} else {
1855
1854
// not the correct variable, but still a variable
0 commit comments