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} ;
22use if_chain:: if_chain;
33use rustc_errors:: Applicability ;
44use rustc_hir:: { Expr , ExprKind , MatchSource } ;
@@ -75,10 +75,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MatchOnVecItems {
7575
7676fn is_vec_indexing < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr < ' tcx > ) -> Option < & ' tcx Expr < ' tcx > > {
7777 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) ;
8281
8382 then {
8483 return Some ( expr) ;
@@ -87,3 +86,15 @@ fn is_vec_indexing<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>)
8786
8887 None
8988}
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