Auto merge of #13273 - alex-semenyuk:assigning_clones_disable_for_test, r=blyxyas
Disable assigning_clones for tests Close: #12752 As mentioned at #12752 when a test struct is initialized with some default string, this inverts the order of assignee/assignment and makes a bit harder to read/write code changelog: [`assigning_clones.rs`]: disable assigning_clones for tests
This commit is contained in:
commit
233b5f2083
@ -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…
x
Reference in New Issue
Block a user