2019-07-16 00:30:23 -05:00
|
|
|
#![warn(clippy::out_of_bounds_indexing)]
|
2022-09-21 06:05:20 -05:00
|
|
|
#![allow(clippy::no_effect, clippy::unnecessary_operation)]
|
2019-07-16 00:30:23 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x = [1, 2, 3, 4];
|
|
|
|
|
|
|
|
&x[..=4];
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: range is out of bounds
|
|
|
|
//~| NOTE: `-D clippy::out-of-bounds-indexing` implied by `-D warnings`
|
2019-07-16 00:30:23 -05:00
|
|
|
&x[1..5];
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: range is out of bounds
|
2019-07-16 00:30:23 -05:00
|
|
|
&x[5..];
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: range is out of bounds
|
2019-07-16 00:30:23 -05:00
|
|
|
&x[..5];
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: range is out of bounds
|
2019-07-16 00:30:23 -05:00
|
|
|
&x[5..].iter().map(|x| 2 * x).collect::<Vec<i32>>();
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: range is out of bounds
|
2019-07-16 00:30:23 -05:00
|
|
|
&x[0..=4];
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: range is out of bounds
|
2019-07-16 00:30:23 -05:00
|
|
|
|
|
|
|
&x[4..]; // Ok, should not produce stderr.
|
|
|
|
&x[..4]; // Ok, should not produce stderr.
|
|
|
|
&x[..]; // Ok, should not produce stderr.
|
|
|
|
&x[1..]; // Ok, should not produce stderr.
|
|
|
|
&x[2..].iter().map(|x| 2 * x).collect::<Vec<i32>>(); // Ok, should not produce stderr.
|
|
|
|
|
|
|
|
&x[0..].get(..3); // Ok, should not produce stderr.
|
|
|
|
&x[0..3]; // Ok, should not produce stderr.
|
|
|
|
}
|