@@ -83,7 +83,7 @@ impl LateLintPass for ArrayIndexing {
83
83
eval_const_expr_partial ( cx. tcx , end, ExprTypeChecked , None ) ) . map ( |v| v. ok ( ) ) ;
84
84
85
85
if let Some ( ( start, end) ) = to_const_range ( start, end, range. limits , size) {
86
- if start >= size || end >= size {
86
+ if start > size || end > size {
87
87
utils:: span_lint ( cx,
88
88
OUT_OF_BOUNDS_INDEXING ,
89
89
e. span ,
@@ -109,14 +109,11 @@ impl LateLintPass for ArrayIndexing {
109
109
}
110
110
}
111
111
112
- /// Returns an option containing a tuple with the start and end (exclusive) of the range
113
- ///
114
- /// Note: we assume the start and the end of the range are unsigned, since array slicing
115
- /// works only on usize
112
+ /// Returns an option containing a tuple with the start and end (exclusive) of the range.
116
113
fn to_const_range ( start : Option < Option < ConstVal > > ,
117
- end : Option < Option < ConstVal > > ,
118
- limits : RangeLimits ,
119
- array_size : ConstInt )
114
+ end : Option < Option < ConstVal > > ,
115
+ limits : RangeLimits ,
116
+ array_size : ConstInt )
120
117
-> Option < ( ConstInt , ConstInt ) > {
121
118
let start = match start {
122
119
Some ( Some ( ConstVal :: Integral ( x) ) ) => x,
@@ -127,13 +124,13 @@ fn to_const_range(start: Option<Option<ConstVal>>,
127
124
let end = match end {
128
125
Some ( Some ( ConstVal :: Integral ( x) ) ) => {
129
126
if limits == RangeLimits :: Closed {
130
- x
127
+ ( x + ConstInt :: Infer ( 1 ) ) . expect ( "such a big array is not realistic" )
131
128
} else {
132
- ( x - ConstInt :: Infer ( 1 ) ) . expect ( "x > 0" )
129
+ x
133
130
}
134
131
}
135
132
Some ( _) => return None ,
136
- None => ( array_size - ConstInt :: Infer ( 1 ) ) . expect ( "array_size > 0" ) ,
133
+ None => array_size
137
134
} ;
138
135
139
136
Some ( ( start, end) )
0 commit comments