| 1 | // Copyright 2023 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Package unusedwrite checks for unused writes to the elements of a struct or array object. |
| 6 | // |
| 7 | // # Analyzer unusedwrite |
| 8 | // |
| 9 | // unusedwrite: checks for unused writes |
| 10 | // |
| 11 | // The analyzer reports instances of writes to struct fields and |
| 12 | // arrays that are never read. Specifically, when a struct object |
| 13 | // or an array is copied, its elements are copied implicitly by |
| 14 | // the compiler, and any element write to this copy does nothing |
| 15 | // with the original object. |
| 16 | // |
| 17 | // For example: |
| 18 | // |
| 19 | // type T struct { x int } |
| 20 | // |
| 21 | // func f(input []T) { |
| 22 | // for i, v := range input { // v is a copy |
| 23 | // v.x = i // unused write to field x |
| 24 | // } |
| 25 | // } |
| 26 | // |
| 27 | // Another example is about non-pointer receiver: |
| 28 | // |
| 29 | // type T struct { x int } |
| 30 | // |
| 31 | // func (t T) f() { // t is a copy |
| 32 | // t.x = i // unused write to field x |
| 33 | // } |
| 34 | package unusedwrite |