Disable assigning_clones for tests

This commit is contained in:
Alexey Semenyuk 2024-08-16 16:17:24 +05:00
parent 5da97d006e
commit 953c7ed41e
3 changed files with 42 additions and 1 deletions

View file

@ -3,7 +3,7 @@ use clippy_config::Conf;
use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::mir::{enclosing_mir, PossibleBorrowerMap}; use clippy_utils::mir::{enclosing_mir, PossibleBorrowerMap};
use clippy_utils::sugg::Sugg; use clippy_utils::sugg::Sugg;
use clippy_utils::{is_diag_trait_item, last_path_segment, local_is_initialized, path_to_local}; use clippy_utils::{is_diag_trait_item, is_in_test, last_path_segment, local_is_initialized, path_to_local};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{self as hir, Expr, ExprKind}; use rustc_hir::{self as hir, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
@ -118,6 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
} }
) )
&& !clone_source_borrows_from_dest(cx, lhs, rhs.span) && !clone_source_borrows_from_dest(cx, lhs, rhs.span)
&& !is_in_test(cx.tcx, e.hir_id)
{ {
span_lint_and_then( span_lint_and_then(
cx, cx,

View file

@ -396,3 +396,23 @@ impl<T: Clone> Clone for DerefWrapperWithClone<T> {
*self = Self(source.0.clone()); *self = Self(source.0.clone());
} }
} }
#[cfg(test)]
mod test {
#[derive(Default)]
struct Data {
field: String,
}
fn test_data() -> Data {
Data {
field: "default_value".to_string(),
}
}
#[test]
fn test() {
let mut data = test_data();
data.field = "override_value".to_owned();
}
}

View file

@ -396,3 +396,23 @@ impl<T: Clone> Clone for DerefWrapperWithClone<T> {
*self = Self(source.0.clone()); *self = Self(source.0.clone());
} }
} }
#[cfg(test)]
mod test {
#[derive(Default)]
struct Data {
field: String,
}
fn test_data() -> Data {
Data {
field: "default_value".to_string(),
}
}
#[test]
fn test() {
let mut data = test_data();
data.field = "override_value".to_owned();
}
}