mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-15 09:27:25 +00:00
Prevent unnecessary lints from triggering
This commit is contained in:
parent
4918e7ad62
commit
5c71352b18
3 changed files with 18 additions and 15 deletions
|
@ -768,12 +768,14 @@ fn check_for_loop<'tcx>(
|
||||||
body: &'tcx Expr<'_>,
|
body: &'tcx Expr<'_>,
|
||||||
expr: &'tcx Expr<'_>,
|
expr: &'tcx Expr<'_>,
|
||||||
) {
|
) {
|
||||||
check_for_loop_range(cx, pat, arg, body, expr);
|
let is_manual_memcpy_triggered = detect_manual_memcpy(cx, pat, arg, body, expr);
|
||||||
|
if !is_manual_memcpy_triggered {
|
||||||
|
check_for_loop_range(cx, pat, arg, body, expr);
|
||||||
|
check_for_loop_explicit_counter(cx, pat, arg, body, expr);
|
||||||
|
}
|
||||||
check_for_loop_arg(cx, pat, arg, expr);
|
check_for_loop_arg(cx, pat, arg, expr);
|
||||||
check_for_loop_explicit_counter(cx, pat, arg, body, expr);
|
|
||||||
check_for_loop_over_map_kv(cx, pat, arg, body, expr);
|
check_for_loop_over_map_kv(cx, pat, arg, body, expr);
|
||||||
check_for_mut_range_bound(cx, arg, body);
|
check_for_mut_range_bound(cx, arg, body);
|
||||||
detect_manual_memcpy(cx, pat, arg, body, expr);
|
|
||||||
detect_same_item_push(cx, pat, arg, body, expr);
|
detect_same_item_push(cx, pat, arg, body, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1152,7 +1154,7 @@ fn detect_manual_memcpy<'tcx>(
|
||||||
arg: &'tcx Expr<'_>,
|
arg: &'tcx Expr<'_>,
|
||||||
body: &'tcx Expr<'_>,
|
body: &'tcx Expr<'_>,
|
||||||
expr: &'tcx Expr<'_>,
|
expr: &'tcx Expr<'_>,
|
||||||
) {
|
) -> bool {
|
||||||
if let Some(higher::Range {
|
if let Some(higher::Range {
|
||||||
start: Some(start),
|
start: Some(start),
|
||||||
end: Some(end),
|
end: Some(end),
|
||||||
|
@ -1222,9 +1224,11 @@ fn detect_manual_memcpy<'tcx>(
|
||||||
big_sugg,
|
big_sugg,
|
||||||
Applicability::Unspecified,
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scans the body of the for loop and determines whether lint should be given
|
// Scans the body of the for loop and determines whether lint should be given
|
||||||
|
|
|
@ -115,7 +115,6 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::needless_range_loop, clippy::explicit_counter_loop)]
|
|
||||||
pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) {
|
pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
for i in 3..src.len() {
|
for i in 3..src.len() {
|
||||||
|
|
|
@ -79,49 +79,49 @@ LL | for i in 0..0 {
|
||||||
| ^^^^ help: try replacing the loop by: `dst[..0].clone_from_slice(&src[..0])`
|
| ^^^^ help: try replacing the loop by: `dst[..0].clone_from_slice(&src[..0])`
|
||||||
|
|
||||||
error: it looks like you're manually copying between slices
|
error: it looks like you're manually copying between slices
|
||||||
--> $DIR/manual_memcpy.rs:121:14
|
--> $DIR/manual_memcpy.rs:120:14
|
||||||
|
|
|
|
||||||
LL | for i in 3..src.len() {
|
LL | for i in 3..src.len() {
|
||||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..src.len()].clone_from_slice(&src[..(src.len() - 3)])`
|
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..src.len()].clone_from_slice(&src[..(src.len() - 3)])`
|
||||||
|
|
||||||
error: it looks like you're manually copying between slices
|
error: it looks like you're manually copying between slices
|
||||||
--> $DIR/manual_memcpy.rs:127:14
|
--> $DIR/manual_memcpy.rs:126:14
|
||||||
|
|
|
|
||||||
LL | for i in 3..src.len() {
|
LL | for i in 3..src.len() {
|
||||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..(src.len() - 3)].clone_from_slice(&src[3..])`
|
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..(src.len() - 3)].clone_from_slice(&src[3..])`
|
||||||
|
|
||||||
error: it looks like you're manually copying between slices
|
error: it looks like you're manually copying between slices
|
||||||
--> $DIR/manual_memcpy.rs:133:14
|
--> $DIR/manual_memcpy.rs:132:14
|
||||||
|
|
|
|
||||||
LL | for i in 0..src.len() {
|
LL | for i in 0..src.len() {
|
||||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..(src.len() + 3)].clone_from_slice(&src[..])`
|
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..(src.len() + 3)].clone_from_slice(&src[..])`
|
||||||
|
|
||||||
error: it looks like you're manually copying between slices
|
error: it looks like you're manually copying between slices
|
||||||
--> $DIR/manual_memcpy.rs:139:14
|
--> $DIR/manual_memcpy.rs:138:14
|
||||||
|
|
|
|
||||||
LL | for i in 0..src.len() {
|
LL | for i in 0..src.len() {
|
||||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[3..(src.len() + 3)])`
|
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[3..(src.len() + 3)])`
|
||||||
|
|
||||||
error: it looks like you're manually copying between slices
|
error: it looks like you're manually copying between slices
|
||||||
--> $DIR/manual_memcpy.rs:145:14
|
--> $DIR/manual_memcpy.rs:144:14
|
||||||
|
|
|
|
||||||
LL | for i in 3..(3 + src.len()) {
|
LL | for i in 3..(3 + src.len()) {
|
||||||
| ^^^^^^^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..((3 + src.len()))].clone_from_slice(&src[..((3 + src.len()) - 3)])`
|
| ^^^^^^^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..((3 + src.len()))].clone_from_slice(&src[..((3 + src.len()) - 3)])`
|
||||||
|
|
||||||
error: it looks like you're manually copying between slices
|
error: it looks like you're manually copying between slices
|
||||||
--> $DIR/manual_memcpy.rs:151:14
|
--> $DIR/manual_memcpy.rs:150:14
|
||||||
|
|
|
|
||||||
LL | for i in 5..src.len() {
|
LL | for i in 5..src.len() {
|
||||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[5..src.len()].clone_from_slice(&src[(3 - 2)..((src.len() - 2) + 3 - 5)])`
|
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[5..src.len()].clone_from_slice(&src[(3 - 2)..((src.len() - 2) + 3 - 5)])`
|
||||||
|
|
||||||
error: it looks like you're manually copying between slices
|
error: it looks like you're manually copying between slices
|
||||||
--> $DIR/manual_memcpy.rs:157:14
|
--> $DIR/manual_memcpy.rs:156:14
|
||||||
|
|
|
|
||||||
LL | for i in 3..10 {
|
LL | for i in 3..10 {
|
||||||
| ^^^^^ help: try replacing the loop by: `dst[3..10].clone_from_slice(&src[5..(10 + 5 - 3)])`
|
| ^^^^^ help: try replacing the loop by: `dst[3..10].clone_from_slice(&src[5..(10 + 5 - 3)])`
|
||||||
|
|
||||||
error: it looks like you're manually copying between slices
|
error: it looks like you're manually copying between slices
|
||||||
--> $DIR/manual_memcpy.rs:164:14
|
--> $DIR/manual_memcpy.rs:163:14
|
||||||
|
|
|
|
||||||
LL | for i in 0..src.len() {
|
LL | for i in 0..src.len() {
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
@ -133,13 +133,13 @@ LL | dst2[30..(src.len() + 30)].clone_from_slice(&src[..]) {
|
||||||
|
|
|
|
||||||
|
|
||||||
error: it looks like you're manually copying between slices
|
error: it looks like you're manually copying between slices
|
||||||
--> $DIR/manual_memcpy.rs:174:14
|
--> $DIR/manual_memcpy.rs:173:14
|
||||||
|
|
|
|
||||||
LL | for i in 0..1 << 1 {
|
LL | for i in 0..1 << 1 {
|
||||||
| ^^^^^^^^^ help: try replacing the loop by: `dst[(0 << 1)..((1 << 1) + (0 << 1))].clone_from_slice(&src[2..((1 << 1) + 2)])`
|
| ^^^^^^^^^ help: try replacing the loop by: `dst[(0 << 1)..((1 << 1) + (0 << 1))].clone_from_slice(&src[2..((1 << 1) + 2)])`
|
||||||
|
|
||||||
error: it looks like you're manually copying between slices
|
error: it looks like you're manually copying between slices
|
||||||
--> $DIR/manual_memcpy.rs:182:14
|
--> $DIR/manual_memcpy.rs:181:14
|
||||||
|
|
|
|
||||||
LL | for i in 0..src.len() {
|
LL | for i in 0..src.len() {
|
||||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..])`
|
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..])`
|
||||||
|
|
Loading…
Reference in a new issue