@@ -168,7 +168,11 @@ impl BlockRangesSequence {
168
168
// End is inclusive, so we need to add 1
169
169
let end = BlockRange :: start ( * interval. end ( ) + 1 ) ;
170
170
171
- Self { start, end }
171
+ if start >= end {
172
+ Self { start : 0 , end : 0 }
173
+ } else {
174
+ Self { start, end }
175
+ }
172
176
}
173
177
174
178
/// Returns the start of the block ranges sequence.
@@ -188,7 +192,7 @@ impl BlockRangesSequence {
188
192
189
193
/// Returns `true` if the block ranges sequence contains no elements.
190
194
pub fn is_empty ( & self ) -> bool {
191
- self . len ( ) == 0
195
+ self . start >= self . end
192
196
}
193
197
194
198
/// Consume `self` into a new Vec
@@ -201,7 +205,7 @@ impl Iterator for BlockRangesSequence {
201
205
type Item = BlockRange ;
202
206
203
207
fn next ( & mut self ) -> Option < Self :: Item > {
204
- if self . start >= self . end {
208
+ if BlockRangesSequence :: is_empty ( self ) {
205
209
return None ;
206
210
}
207
211
@@ -402,4 +406,13 @@ mod tests {
402
406
BlockRange :: from_block_number_and_length ( 10 , 0 )
403
407
. expect_err ( "BlockRange should not be computed with a length of 0" ) ;
404
408
}
409
+
410
+ #[ test]
411
+ // allow to specify a range with start > end
412
+ #[ allow( clippy:: reversed_empty_ranges) ]
413
+ fn test_building_sequence_with_start_greater_than_end_yield_empty_iterator ( ) {
414
+ let sequence = BlockRange :: all_block_ranges_in ( 30 ..=15 ) ;
415
+ assert_eq ! ( sequence. clone( ) . into_vec( ) , vec![ ] ) ;
416
+ assert ! ( sequence. is_empty( ) ) ;
417
+ }
405
418
}
0 commit comments