# How Go's vet catches copies of sync.Mutex and noCopy

Original title: How Go detects struct copies with sync.noCopy

> Hacker News story 49284983 · language: en · submitted 2026-08-13
> Web version: https://zeli.app/story/49284983
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 3 · by [func25](<https://news.ycombinator.com/user?id=func25>) · 💬 1
[original](<https://func25.dev/posts/go-sync-nocopy/>) · [HN discussion](<https://news.ycombinator.com/item?id=49284983>)

## Summary

Go's sync package uses a zero-size noCopy marker to prevent copying types like sync.Mutex and sync.Map. The marker works with go vet's copylocks checker, which flags copies of types that implement sync.Locker only via pointer. The checker recursively inspects struct fields, so even types that embed noCopy indirectly are caught. This article explains the mechanism, why noCopy has Lock and Unlock methods, and how to add the marker to your own types. It also covers edge cases like sync.RWMutex and the impact of field placement on struct size.

## Key quote

> The marker still cannot stop the compiler from copying a value.

## HN discussion (1 comments)

### [meerita](<https://news.ycombinator.com/item?id=49331760>)

> I spoke with Aliaksandr Valialkin (author of noCopy) and he gave me his reasons:
>
> \- https://x.com/valyala/status/2088638160242683954
>
> He also gave an answer of what he would change now: https://itnext.io/go-evolves-in-the-wrong-direction-7dfda8a1...
>
> It seems he's not happy anymore with the new direction of Go because they're implementing things from other languages.

### [woadwarrior01](<https://news.ycombinator.com/item?id=49329505>)

> \> noCopy is a special marker for types that must not be copied after their first use.
>
> if it looks like a hack, walks like a hack, and quacks like a hack...

### [CamouflagedKiwi](<https://news.ycombinator.com/item?id=49329831>)

> This feels like it should ideally be something public in the structs package so anyone can leverage it, not just a specially blessed internal thing for the sync package.

### [fithisux](<https://news.ycombinator.com/item?id=49332024>)

> Very good article. Interesting approach working in harmony with `go vet`.

---

## Cite

- Page: https://zeli.app/story/49284983
- Date: 2026-08-13
- Source: func25.dev (https://func25.dev/posts/go-sync-nocopy/)
- Hacker News: https://news.ycombinator.com/item?id=49284983

## Other languages

- zh: https://zeli.app/zh/story/49284983 · markdown: https://zeli.app/zh/story/49284983.md
- ja: https://zeli.app/ja/story/49284983 · markdown: https://zeli.app/ja/story/49284983.md
- ko: https://zeli.app/ko/story/49284983 · markdown: https://zeli.app/ko/story/49284983.md
- de: https://zeli.app/de/story/49284983 · markdown: https://zeli.app/de/story/49284983.md
- es: https://zeli.app/es/story/49284983 · markdown: https://zeli.app/es/story/49284983.md
