]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/needless_range_loop.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / needless_range_loop.rs
index 30613f98f2bce3be8a6b8d8668d235cd74019801..f3d47eede48b6c750b38f3fbed792536145935b9 100644 (file)
@@ -1,9 +1,18 @@
+// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
 fn calc_idx(i: usize) -> usize {
     (i + i + 20) % 4
 }
 
 fn main() {
-    let ns = [2, 3, 5, 7];
+    let ns = vec![2, 3, 5, 7];
 
     for i in 3..10 {
         println!("{}", ns[i]);
@@ -41,7 +50,7 @@ fn main() {
     let g = vec![1, 2, 3, 4, 5, 6];
     let glen = g.len();
     for i in 0..glen {
-        let x: u32 = g[i+1..].iter().sum();
+        let x: u32 = g[i + 1..].iter().sum();
         println!("{}", g[i] + x);
     }
     assert_eq!(g, vec![20, 18, 15, 11, 6, 0]);
@@ -49,7 +58,35 @@ fn main() {
     let mut g = vec![1, 2, 3, 4, 5, 6];
     let glen = g.len();
     for i in 0..glen {
-        g[i] = g[i+1..].iter().sum();
+        g[i] = g[i + 1..].iter().sum();
     }
     assert_eq!(g, vec![20, 18, 15, 11, 6, 0]);
+
+    let x = 5;
+    let mut vec = vec![0; 9];
+
+    for i in x..x + 4 {
+        vec[i] += 1;
+    }
+
+    let x = 5;
+    let mut vec = vec![0; 10];
+
+    for i in x..=x + 4 {
+        vec[i] += 1;
+    }
+
+    let arr = [1, 2, 3];
+
+    for i in 0..3 {
+        println!("{}", arr[i]);
+    }
+
+    for i in 0..2 {
+        println!("{}", arr[i]);
+    }
+
+    for i in 1..3 {
+        println!("{}", arr[i]);
+    }
 }