@@ -22,6 +22,7 @@ mod needless_bitwise_bool;
2222mod numeric_arithmetic;
2323mod op_ref;
2424mod ptr_eq;
25+ mod self_assignment;
2526mod verbose_bit_mask;
2627
2728declare_clippy_lint ! {
@@ -701,6 +702,37 @@ declare_clippy_lint! {
701702 "use `std::ptr::eq` when comparing raw pointers"
702703}
703704
705+ declare_clippy_lint ! {
706+ /// ### What it does
707+ /// Checks for explicit self-assignments.
708+ ///
709+ /// ### Why is this bad?
710+ /// Self-assignments are redundant and unlikely to be
711+ /// intentional.
712+ ///
713+ /// ### Known problems
714+ /// If expression contains any deref coercions or
715+ /// indexing operations they are assumed not to have any side effects.
716+ ///
717+ /// ### Example
718+ /// ```rust
719+ /// struct Event {
720+ /// id: usize,
721+ /// x: i32,
722+ /// y: i32,
723+ /// }
724+ ///
725+ /// fn copy_position(a: &mut Event, b: &Event) {
726+ /// a.x = b.x;
727+ /// a.y = a.y;
728+ /// }
729+ /// ```
730+ #[ clippy:: version = "1.48.0" ]
731+ pub SELF_ASSIGNMENT ,
732+ correctness,
733+ "explicit self-assignment"
734+ }
735+
704736pub struct Operators {
705737 arithmetic_context : numeric_arithmetic:: Context ,
706738 verbose_bit_mask_threshold : u64 ,
@@ -730,6 +762,7 @@ impl_lint_pass!(Operators => [
730762 MODULO_ARITHMETIC ,
731763 NEEDLESS_BITWISE_BOOL ,
732764 PTR_EQ ,
765+ SELF_ASSIGNMENT ,
733766] ) ;
734767impl Operators {
735768 pub fn new ( verbose_bit_mask_threshold : u64 ) -> Self {
@@ -775,6 +808,7 @@ impl<'tcx> LateLintPass<'tcx> for Operators {
775808 } ,
776809 ExprKind :: Assign ( lhs, rhs, _) => {
777810 assign_op_pattern:: check ( cx, e, lhs, rhs) ;
811+ self_assignment:: check ( cx, e, lhs, rhs) ;
778812 } ,
779813 ExprKind :: Unary ( op, arg) => {
780814 if op == UnOp :: Neg {
0 commit comments