From c23a457e72abe608715ac76f076f47dc42af07a5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 20:31:44 +0200 Subject: Merging upstream version 1.74.1+dfsg1. Signed-off-by: Daniel Baumann --- src/tools/clippy/tests/ui/needless_range_loop2.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/tools/clippy/tests/ui/needless_range_loop2.rs') diff --git a/src/tools/clippy/tests/ui/needless_range_loop2.rs b/src/tools/clippy/tests/ui/needless_range_loop2.rs index 516d99a35..787ff18f3 100644 --- a/src/tools/clippy/tests/ui/needless_range_loop2.rs +++ b/src/tools/clippy/tests/ui/needless_range_loop2.rs @@ -1,6 +1,6 @@ #![warn(clippy::needless_range_loop)] #![allow(clippy::useless_vec)] - +//@no-rustfix fn calc_idx(i: usize) -> usize { (i + i + 20) % 4 } @@ -9,6 +9,8 @@ fn main() { let ns = vec![2, 3, 5, 7]; for i in 3..10 { + //~^ ERROR: the loop variable `i` is only used to index `ns` + //~| NOTE: `-D clippy::needless-range-loop` implied by `-D warnings` println!("{}", ns[i]); } @@ -30,12 +32,14 @@ fn main() { let mut ms = vec![1, 2, 3, 4, 5, 6]; for i in 0..ms.len() { + //~^ ERROR: the loop variable `i` is only used to index `ms` ms[i] *= 2; } assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]); let mut ms = vec![1, 2, 3, 4, 5, 6]; for i in 0..ms.len() { + //~^ ERROR: the loop variable `i` is only used to index `ms` let x = &mut ms[i]; *x *= 2; } @@ -60,6 +64,7 @@ fn main() { let mut vec = vec![0; 9]; for i in x..x + 4 { + //~^ ERROR: the loop variable `i` is only used to index `vec` vec[i] += 1; } @@ -67,20 +72,24 @@ fn main() { let mut vec = vec![0; 10]; for i in x..=x + 4 { + //~^ ERROR: the loop variable `i` is only used to index `vec` vec[i] += 1; } let arr = [1, 2, 3]; for i in 0..3 { + //~^ ERROR: the loop variable `i` is only used to index `arr` println!("{}", arr[i]); } for i in 0..2 { + //~^ ERROR: the loop variable `i` is only used to index `arr` println!("{}", arr[i]); } for i in 1..3 { + //~^ ERROR: the loop variable `i` is only used to index `arr` println!("{}", arr[i]); } -- cgit v1.2.3