@@ -69,34 +69,26 @@ impl LateLintPass for ArrayIndexing {
69
69
if let Ok ( ConstVal :: Uint ( const_index) ) = const_index {
70
70
if size <= const_index {
71
71
utils:: span_lint ( cx, OUT_OF_BOUNDS_INDEXING , e. span , "const index is out of bounds" ) ;
72
- utils:: span_lint ( cx, INDEXING_SLICING , e. span , "indexing may panic" ) ;
73
- } else {
74
- // Index is within bounds
75
- return ;
76
72
}
73
+
74
+ return ;
77
75
}
78
76
79
77
// Index is a constant range
80
78
if let Some ( range) = utils:: unsugar_range ( index) {
81
79
let start = range. start . map ( |start|
82
- eval_const_expr_partial ( cx. tcx , start, ExprTypeChecked , None ) ) ;
80
+ eval_const_expr_partial ( cx. tcx , start, ExprTypeChecked , None ) ) . map ( |v| v . ok ( ) ) ;
83
81
let end = range. end . map ( |end|
84
- eval_const_expr_partial ( cx. tcx , end, ExprTypeChecked , None ) ) ;
82
+ eval_const_expr_partial ( cx. tcx , end, ExprTypeChecked , None ) ) . map ( |v| v . ok ( ) ) ;
85
83
86
84
if let Some ( ( start, end) ) = to_const_range ( start, end, range. limits , size) {
87
- if start >= size && end >= size {
85
+ if start >= size || end >= size {
88
86
utils:: span_lint ( cx,
89
87
OUT_OF_BOUNDS_INDEXING ,
90
88
e. span ,
91
89
"range is out of bounds" ) ;
92
- utils:: span_lint ( cx,
93
- INDEXING_SLICING ,
94
- e. span ,
95
- "slicing may panic" ) ;
96
- } else {
97
- // Range is within bounds
98
- return ;
99
90
}
91
+ return ;
100
92
}
101
93
}
102
94
}
@@ -120,19 +112,19 @@ impl LateLintPass for ArrayIndexing {
120
112
///
121
113
/// Note: we assume the start and the end of the range are unsigned, since array slicing
122
114
/// works only on usize
123
- fn to_const_range < T > ( start : Option < Result < ConstVal , T > > ,
124
- end : Option < Result < ConstVal , T > > ,
115
+ fn to_const_range ( start : Option < Option < ConstVal > > ,
116
+ end : Option < Option < ConstVal > > ,
125
117
limits : RangeLimits ,
126
118
array_size : u64 )
127
119
-> Option < ( u64 , u64 ) > {
128
120
let start = match start {
129
- Some ( Ok ( ConstVal :: Uint ( x) ) ) => x,
121
+ Some ( Some ( ConstVal :: Uint ( x) ) ) => x,
130
122
Some ( _) => return None ,
131
123
None => 0 ,
132
124
} ;
133
125
134
126
let end = match end {
135
- Some ( Ok ( ConstVal :: Uint ( x) ) ) => {
127
+ Some ( Some ( ConstVal :: Uint ( x) ) ) => {
136
128
if limits == RangeLimits :: Closed {
137
129
x
138
130
} else {
0 commit comments