| 1 |
//go:build go1.23 |
| 2 |
|
| 3 |
package mapsloop |
| 4 |
|
| 5 |
import . "maps" |
| 6 |
|
| 7 |
var _ = Clone[M] // force "maps" import so that each diagnostic doesn't add one |
| 8 |
|
| 9 |
func useCopyDot(dst, src map[int]string) { |
| 10 |
// Replace loop by maps.Copy. |
| 11 |
// want "Replace m\\[k\\]=v loop with maps.Copy" |
| 12 |
Copy(dst, src) |
| 13 |
} |
| 14 |
|
| 15 |
func useCloneDot(src map[int]string) { |
| 16 |
// Clone is tempting but wrong when src may be nil; see #71844. |
| 17 |
|
| 18 |
// Replace make(...) by maps.Copy. |
| 19 |
dst := make(map[int]string, len(src)) |
| 20 |
// want "Replace m\\[k\\]=v loop with maps.Copy" |
| 21 |
Copy(dst, src) |
| 22 |
println(dst) |
| 23 |
} |