mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Disable assigning_clones for tests
This commit is contained in:
parent
5da97d006e
commit
953c7ed41e
3 changed files with 42 additions and 1 deletions
|
@ -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,
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue