Skip to content

Commit 4ea4a97

Browse files
committed
Add tests for bitwise operations
1 parent 9aad38b commit 4ea4a97

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

tests/ui/manual_memcpy.rs

+8
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32])
167167
count += 1;
168168
count += 1;
169169
}
170+
171+
// make sure parentheses are added properly to bitwise operators, which have lower precedence than
172+
// arithmetric ones
173+
let mut count = 0 << 1;
174+
for i in 0..1 << 1 {
175+
dst[count] = src[i + 2];
176+
count += 1;
177+
}
170178
}
171179

172180
#[warn(clippy::needless_range_loop, clippy::manual_memcpy)]

tests/ui/manual_memcpy.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,14 @@ LL | dst2[30..(src.len() + 30)].clone_from_slice(&src[..]) {
135135
error: it looks like you're manually copying between slices
136136
--> $DIR/manual_memcpy.rs:174:14
137137
|
138+
LL | for i in 0..1 << 1 {
139+
| ^^^^^^^^^ help: try replacing the loop by: `dst[(0 << 1)..((1 << 1) + (0 << 1))].clone_from_slice(&src[2..((1 << 1) + 2)])`
140+
141+
error: it looks like you're manually copying between slices
142+
--> $DIR/manual_memcpy.rs:182:14
143+
|
138144
LL | for i in 0..src.len() {
139145
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..])`
140146

141-
error: aborting due to 21 previous errors
147+
error: aborting due to 22 previous errors
142148

0 commit comments

Comments
 (0)