Skip to content

Commit

Permalink
Disable assigning_clones for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-semenyuk committed Aug 16, 2024
1 parent 5da97d0 commit 953c7ed
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clippy_lints/src/assigning_clones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clippy_config::Conf;
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::mir::{enclosing_mir, PossibleBorrowerMap};
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_hir::{self as hir, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
Expand Down Expand Up @@ -118,6 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
}
)
&& !clone_source_borrows_from_dest(cx, lhs, rhs.span)
&& !is_in_test(cx.tcx, e.hir_id)
{
span_lint_and_then(
cx,
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/assigning_clones.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,23 @@ impl<T: Clone> Clone for DerefWrapperWithClone<T> {
*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();
}
}
20 changes: 20 additions & 0 deletions tests/ui/assigning_clones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,23 @@ impl<T: Clone> Clone for DerefWrapperWithClone<T> {
*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();
}
}

0 comments on commit 953c7ed

Please sign in to comment.