Amanieu / parking_lot

Compact and efficient synchronization primitives for Rust. Also provides an API for creating custom synchronization primitives.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ReentrantMutexGuard::try_map exposes unsound mutable borrow

wabain opened this issue · comments

A ReentrantMutex is supposed to only directly expose immutable references to its contents in order to allow multiple overlapping borrows from the same thread. However, as of lock_api 0.4.8 ReentrantMutexGuard::<T>::try_map exposes a mutable reference to T; it calls a function of type F: FnOnce(&mut T) -> Option<&mut U>.

It looks to me like this was some kind of porting error that retained the signature from MutexGuard::try_map. The mutability isn't called out in the docs and the implementation doesn't account for the case where another remutex guard is borrowing the data, as far as I can see. The rest of the {Mapped,}ReentrantMutexGuard::{try_,}map functions all go from &T to &U, as I would expect.