Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RwLock*Guard::map to not allow escaping a reference to the data. #31440

Merged
merged 1 commit into from
Feb 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/libstd/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,11 @@ impl<'rwlock, T: ?Sized> RwLockReadGuard<'rwlock, T> {
/// assert_eq!(*y, 1);
/// ```
#[unstable(feature = "guard_map",
reason = "recently added, needs RFC for stabilization",
reason = "recently added, needs RFC for stabilization,
questionable interaction with Condvar",
issue = "27746")]
pub fn map<U: ?Sized, F>(this: Self, cb: F) -> RwLockReadGuard<'rwlock, U>
where F: FnOnce(&'rwlock T) -> &'rwlock U
where F: FnOnce(&T) -> &U
{
let new = RwLockReadGuard {
__lock: this.__lock,
Expand Down Expand Up @@ -504,10 +505,11 @@ impl<'rwlock, T: ?Sized> RwLockWriteGuard<'rwlock, T> {
/// assert_eq!(&**x.read().unwrap(), &[10, 2]);
/// ```
#[unstable(feature = "guard_map",
reason = "recently added, needs RFC for stabilization",
reason = "recently added, needs RFC for stabilization,
questionable interaction with Condvar",
issue = "27746")]
pub fn map<U: ?Sized, F>(this: Self, cb: F) -> RwLockWriteGuard<'rwlock, U>
where F: FnOnce(&'rwlock mut T) -> &'rwlock mut U
where F: FnOnce(&mut T) -> &mut U
{
// Compute the new data while still owning the original lock
// in order to correctly poison if the callback panics.
Expand Down