go icon indicating copy to clipboard operation
go copied to clipboard

sync: incorrect documentation for `(*RWMutex).RLocker`

Open gazerro opened this issue 1 year ago • 4 comments

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.

gazerro avatar Jun 29 '24 16:06 gazerro

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

gabyhelp avatar Jun 29 '24 16:06 gabyhelp

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 avatar Jun 29 '24 17:06 MikeMitchellWebDev

@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.

gazerro avatar Jun 29 '24 17:06 gazerro

Change https://go.dev/cl/595875 mentions this issue: sync: refer to Locker interface methods in RWMutex.RLocker doc

gopherbot avatar Jun 29 '24 20:06 gopherbot