| 1 |
package appendclipped |
| 2 |
|
| 3 |
import ( |
| 4 |
"os" |
| 5 |
"slices" |
| 6 |
) |
| 7 |
|
| 8 |
type ( |
| 9 |
Bytes []byte |
| 10 |
Bytes2 []byte |
| 11 |
) |
| 12 |
|
| 13 |
func _(s, other []string) { |
| 14 |
print(slices.Clone(s)) // want "Replace append with slices.Clone" |
| 15 |
print(slices.Clone(s)) // want "Replace append with slices.Clone" |
| 16 |
print(slices.Clone(Bytes{1, 2, 3})) // want "Replace append with slices.Clone" |
| 17 |
print(slices.Clone(s)) // want "Replace append with slices.Clone" |
| 18 |
print(os.Environ()) // want "Redundant clone of os.Environ()" |
| 19 |
print(append(other[:0], s...)) // nope: intent may be to mutate other |
| 20 |
|
| 21 |
print(slices.Concat(s, other, other)) // want "Replace append with slices.Concat" |
| 22 |
print(slices.Concat(s, other, other)) // want "Replace append with slices.Concat" |
| 23 |
print(slices.Concat(Bytes{1, 2, 3}, Bytes{4, 5, 6})) // want "Replace append with slices.Concat" |
| 24 |
print(slices.Concat(s, other, other)) // want "Replace append with slices.Concat" |
| 25 |
print(slices.Concat(os.Environ(), other, other)) // want "Replace append with slices.Concat" |
| 26 |
print(slices.Concat(other, s, other)) // want "Replace append with slices.Concat" |
| 27 |
print(slices.Concat(other, s, other)) // want "Replace append with slices.Concat" |
| 28 |
print(append(append(append(other[:0], s...), other...), other...)) // nope: intent may be to mutate other |
| 29 |
} |
| 30 |
|
| 31 |
var ( |
| 32 |
_ Bytes = append(Bytes(nil), []byte(nil)...) // nope: correct fix requires Clone[Bytes] (#73661) |
| 33 |
_ Bytes = append([]byte(nil), Bytes(nil)...) // nope: correct fix requires Clone[Bytes] (#73661) |
| 34 |
_ Bytes2 = append([]byte(nil), Bytes(nil)...) // nope: correct fix requires Clone[Bytes2] (#73661) |
| 35 |
) |