go
go copied to clipboard
sync: incorrect documentation for `(*RWMutex).RLocker`
Commit cab90c8 has incorrectly changed the documentation of (*sync.RWMutex).RLocker to reference RWMutex.Lock and RWMutex.Unlock instead of Locker.Lock and Locker.Unlock:
// RLocker returns a [Locker] interface that implements
// the [RWMutex.Lock] and [RWMutex.Unlock] methods by calling rw.RLock and rw.RUnlock.
The correct documentation should be
// RLocker returns a [Locker] interface that implements
// the Lock and Unlock methods by calling rw.RLock and rw.RUnlock.
Related Issues
-
[Package sync > type RWMutex ¶
\> func (\*RWMutex) RLocker ¶ ](https://go.dev/pkg/sync/?m=old#RWMutex.RLocker) <!-- score=0.85125 --> -
sync: deemphasize goroutines in RWMutex documentation #41555 (closed)
-
sync: document more clearly sync.RWMutex doesn't support lock upgrades/downgrades #38859
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Wouldn't it be sufficient to say "// RLocker returns a [Locker] interface" since it wouldn't be a Locker interface unless the Lock and Unlock methods had been implemented by rlocker. It's redundant to say anything more unless you're trying to educate about what an interface is but that's probably not necessary here.
@MikeMitchellWebDev No, because *RWMutex already implements the Locker interface. The purpose of the RLocker method is to return an implementation of Locker that uses *RWMutex.RLock instead of *RWMutex.Lock and *RWMutex.RUnlock instead of *RWMutex.Unlock. Therefore, it is essential to document this behavior explicitly.
Change https://go.dev/cl/595875 mentions this issue: sync: refer to Locker interface methods in RWMutex.RLocker doc