]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs
bump version to 1.77.2+dfsg1-1~bpo12+pve1
[rustc.git] / src / tools / clippy / tests / ui / out_of_bounds_indexing / simple.rs
CommitLineData
f20569fa 1#![warn(clippy::out_of_bounds_indexing)]
2b03887a 2#![allow(clippy::no_effect, clippy::unnecessary_operation)]
f20569fa
XL
3
4fn main() {
5 let x = [1, 2, 3, 4];
6
7 &x[..=4];
781aab86
FG
8 //~^ ERROR: range is out of bounds
9 //~| NOTE: `-D clippy::out-of-bounds-indexing` implied by `-D warnings`
f20569fa 10 &x[1..5];
781aab86 11 //~^ ERROR: range is out of bounds
f20569fa 12 &x[5..];
781aab86 13 //~^ ERROR: range is out of bounds
f20569fa 14 &x[..5];
781aab86 15 //~^ ERROR: range is out of bounds
f20569fa 16 &x[5..].iter().map(|x| 2 * x).collect::<Vec<i32>>();
781aab86 17 //~^ ERROR: range is out of bounds
f20569fa 18 &x[0..=4];
781aab86 19 //~^ ERROR: range is out of bounds
f20569fa
XL
20
21 &x[4..]; // Ok, should not produce stderr.
22 &x[..4]; // Ok, should not produce stderr.
23 &x[..]; // Ok, should not produce stderr.
24 &x[1..]; // Ok, should not produce stderr.
25 &x[2..].iter().map(|x| 2 * x).collect::<Vec<i32>>(); // Ok, should not produce stderr.
26
27 &x[0..].get(..3); // Ok, should not produce stderr.
28 &x[0..3]; // Ok, should not produce stderr.
29}