An exported struct embeds a mutex, which makes Lock and Unlock part of its API
What it finds
type Cache struct { sync.Mutex; items map[string]int }: an embedded mutex promotes Lock and Unlock to methods of the exported type, so any user of the package can lock the cache and the locking becomes part of its API. A named, unexported field keeps the lock inside the package.
Reported are sync.Mutex and sync.RWMutex embedded, without a pointer, in an exported struct type.
From the rule's source, exported_embedded_mutex.rs.
package p import "sync" type Cache struct { sync.Mutextx0 reports: embedding sync.Mutex exports its Lock and Unlock items map[string]int} type store struct { sync.Mutex} type Safe struct { mu sync.Mutex} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/go:exported-embedded-mutex" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:exported-embedded-mutex] reason="..."tx0 explain tx0/go:exported-embedded-mutex shows the same in the terminal. Found a false positive? Report it.