summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs')
-rw-r--r--src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs b/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs
new file mode 100644
index 000000000..590e578d7
--- /dev/null
+++ b/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs
@@ -0,0 +1,22 @@
+#![warn(clippy::out_of_bounds_indexing)]
+#![allow(clippy::no_effect, clippy::unnecessary_operation, const_err)]
+
+fn main() {
+ let x = [1, 2, 3, 4];
+
+ &x[..=4];
+ &x[1..5];
+ &x[5..];
+ &x[..5];
+ &x[5..].iter().map(|x| 2 * x).collect::<Vec<i32>>();
+ &x[0..=4];
+
+ &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.
+}