about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-08-16 21:56:37 +0000
committerbors <bors@rust-lang.org>2020-08-16 21:56:37 +0000
commit8332fe81d888aaa081bf85e5695eaabd2624ea73 (patch)
treed44d58b8093ea749dd64d37f188c41a9bc7a9e1c /src
parent8d0d89adc81be1fa7766ff17aa4f2c6d5e8c69f7 (diff)
parent4f4abf4e0640edbb1614f3dcb8ff62e8afc54801 (diff)
downloadrust-8332fe81d888aaa081bf85e5695eaabd2624ea73.tar.gz
rust-8332fe81d888aaa081bf85e5695eaabd2624ea73.zip
Auto merge of #5894 - tmiasko:self-assignment, r=Manishearth
Warn about explicit self-assignment

Warn about assignments where left-hand side place expression is the same
as right-hand side value expression. For example, warn about assignment in:

```rust
pub struct Event {
    id: usize,
    x: i32,
    y: i32,
}

pub fn copy_position(a: &mut Event, b: &Event) {
    a.x = b.x;
    a.y = a.y;
}
```

changelog: New lint `self_assignment`, checks for explicit self-assignments.
Diffstat (limited to 'src')
-rw-r--r--src/lintlist/mod.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs
index 3229c8da507..bf58c117aaa 100644
--- a/src/lintlist/mod.rs
+++ b/src/lintlist/mod.rs
@@ -1957,6 +1957,13 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "methods",
     },
     Lint {
+        name: "self_assignment",
+        group: "correctness",
+        desc: "explicit self-assignment",
+        deprecation: None,
+        module: "self_assignment",
+    },
+    Lint {
         name: "serde_api_misuse",
         group: "correctness",
         desc: "various things that will negatively affect your serde experience",