1
- use crate :: utils:: { is_type_diagnostic_item, snippet, span_lint_and_sugg, walk_ptrs_ty} ;
1
+ use crate :: utils:: { is_type_diagnostic_item, match_type , snippet, span_lint_and_sugg, walk_ptrs_ty} ;
2
2
use if_chain:: if_chain;
3
3
use rustc_errors:: Applicability ;
4
4
use rustc_hir:: { Expr , ExprKind , MatchSource } ;
@@ -75,10 +75,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MatchOnVecItems {
75
75
76
76
fn is_vec_indexing < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr < ' tcx > ) -> Option < & ' tcx Expr < ' tcx > > {
77
77
if_chain ! {
78
- if let ExprKind :: Index ( ref array, _) = expr. kind;
79
- let ty = cx. tables. expr_ty( array) ;
80
- let ty = walk_ptrs_ty( ty) ;
81
- if is_type_diagnostic_item( cx, ty, sym!( vec_type) ) ;
78
+ if let ExprKind :: Index ( ref array, ref index) = expr. kind;
79
+ if is_vector( cx, array) ;
80
+ if !is_full_range( cx, index) ;
82
81
83
82
then {
84
83
return Some ( expr) ;
@@ -87,3 +86,15 @@ fn is_vec_indexing<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>)
87
86
88
87
None
89
88
}
89
+
90
+ fn is_vector ( cx : & LateContext < ' _ , ' _ > , expr : & Expr < ' _ > ) -> bool {
91
+ let ty = cx. tables . expr_ty ( expr) ;
92
+ let ty = walk_ptrs_ty ( ty) ;
93
+ is_type_diagnostic_item ( cx, ty, sym ! ( vec_type) )
94
+ }
95
+
96
+ fn is_full_range ( cx : & LateContext < ' _ , ' _ > , expr : & Expr < ' _ > ) -> bool {
97
+ let ty = cx. tables . expr_ty ( expr) ;
98
+ let ty = walk_ptrs_ty ( ty) ;
99
+ match_type ( cx, ty, & [ "core" , "ops" , "range" , "RangeFull" ] )
100
+ }
0 commit comments