@@ -33,51 +33,47 @@ impl<'tcx> LateLintPass<'tcx> for SecurityIndexingUsage {
3333 context : & LateContext < ' tcx > ,
3434 expression : & ' tcx Expr < ' tcx > ,
3535 ) {
36- match & expression. kind {
37- ExprKind :: Index ( _, index_expr, _) => {
38- match & index_expr. kind {
39- // Literal indexing: array[0].
40- ExprKind :: Lit ( _) => {
41- context. span_lint (
42- SECURITY_INDEXING_USAGE ,
43- expression. span ,
44- |diagnostic : & mut Diag < ' _ , ( ) > | {
45- diagnostic. primary_message (
46- "Usage of indexing operation detected." ,
47- ) ;
48- } ,
49- ) ;
50- } ,
36+ if let ExprKind :: Index ( _, index_expr, _) = & expression. kind {
37+ match & index_expr. kind {
38+ // Literal indexing: array[0].
39+ ExprKind :: Lit ( _) => {
40+ context. span_lint (
41+ SECURITY_INDEXING_USAGE ,
42+ expression. span ,
43+ |diagnostic : & mut Diag < ' _ , ( ) > | {
44+ diagnostic. primary_message (
45+ "Usage of indexing operation detected." ,
46+ ) ;
47+ } ,
48+ ) ;
49+ } ,
5150
52- // Range slicing: array[1..], array[..], array[a..b].
53- ExprKind :: Struct ( _, _, _) => {
54- context. span_lint (
55- SECURITY_INDEXING_USAGE ,
56- expression. span ,
57- |diagnostic : & mut Diag < ' _ , ( ) > | {
58- diagnostic. primary_message (
59- "Usage of slicing operation detected." ,
60- ) ;
61- } ,
62- ) ;
63- } ,
51+ // Range slicing: array[1..], array[..], array[a..b].
52+ ExprKind :: Struct ( _, _, _) => {
53+ context. span_lint (
54+ SECURITY_INDEXING_USAGE ,
55+ expression. span ,
56+ |diagnostic : & mut Diag < ' _ , ( ) > | {
57+ diagnostic. primary_message (
58+ "Usage of slicing operation detected." ,
59+ ) ;
60+ } ,
61+ ) ;
62+ } ,
6463
65- // Any other dynamic indexing: array[i].
66- _ => {
67- context. span_lint (
68- SECURITY_INDEXING_USAGE ,
69- expression. span ,
70- |diagnostic : & mut Diag < ' _ , ( ) > | {
71- diagnostic. primary_message (
72- "Usage of indexing operation detected." ,
73- ) ;
74- } ,
75- ) ;
76- } ,
77- }
78- } ,
79-
80- _ => { } ,
64+ // Any other dynamic indexing: array[i].
65+ _ => {
66+ context. span_lint (
67+ SECURITY_INDEXING_USAGE ,
68+ expression. span ,
69+ |diagnostic : & mut Diag < ' _ , ( ) > | {
70+ diagnostic. primary_message (
71+ "Usage of indexing operation detected." ,
72+ ) ;
73+ } ,
74+ ) ;
75+ } ,
76+ }
8177 }
8278 }
8379
@@ -97,20 +93,18 @@ impl<'tcx> LateLintPass<'tcx> for SecurityIndexingUsage {
9793 if let ItemKind :: Impl ( implementation) = & item. kind
9894 && let Some ( trait_ref) = implementation. of_trait
9995 && let Some ( def_id) = trait_ref. trait_ref . path . res . opt_def_id ( )
96+ && ( context. tcx . lang_items ( ) . index_trait ( ) == Some ( def_id)
97+ || context. tcx . lang_items ( ) . index_mut_trait ( ) == Some ( def_id) )
10098 {
101- if context. tcx . lang_items ( ) . index_trait ( ) == Some ( def_id)
102- || context. tcx . lang_items ( ) . index_mut_trait ( ) == Some ( def_id)
103- {
104- context. span_lint (
105- SECURITY_INDEXING_USAGE ,
106- item. span ,
107- |diagnostic : & mut Diag < ' _ , ( ) > | {
108- diagnostic. primary_message (
109- "Implementation of Index/IndexMut trait detected." ,
110- ) ;
111- } ,
112- ) ;
113- }
99+ context. span_lint (
100+ SECURITY_INDEXING_USAGE ,
101+ item. span ,
102+ |diagnostic : & mut Diag < ' _ , ( ) > | {
103+ diagnostic. primary_message (
104+ "Implementation of Index/IndexMut trait detected." ,
105+ ) ;
106+ } ,
107+ ) ;
114108 }
115109 }
116110}
0 commit comments