@@ -177,8 +177,10 @@ impl<T: ?Sized> RwLock<T> {
177177 #[ inline]
178178 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
179179 pub fn read ( & self ) -> LockResult < RwLockReadGuard < T > > {
180- unsafe { self . inner . lock . read ( ) }
181- unsafe { RwLockReadGuard :: new ( & * self . inner , & self . data ) }
180+ unsafe {
181+ self . inner . lock . read ( ) ;
182+ RwLockReadGuard :: new ( & * self . inner , & self . data )
183+ }
182184 }
183185
184186 /// Attempts to acquire this rwlock with shared read access.
@@ -201,10 +203,12 @@ impl<T: ?Sized> RwLock<T> {
201203 #[ inline]
202204 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
203205 pub fn try_read ( & self ) -> TryLockResult < RwLockReadGuard < T > > {
204- if unsafe { self . inner . lock . try_read ( ) } {
205- Ok ( try!( unsafe { RwLockReadGuard :: new ( & * self . inner , & self . data ) } ) )
206- } else {
207- Err ( TryLockError :: WouldBlock )
206+ unsafe {
207+ if self . inner . lock . try_read ( ) {
208+ Ok ( try!( RwLockReadGuard :: new ( & * self . inner , & self . data ) ) )
209+ } else {
210+ Err ( TryLockError :: WouldBlock )
211+ }
208212 }
209213 }
210214
@@ -225,8 +229,10 @@ impl<T: ?Sized> RwLock<T> {
225229 #[ inline]
226230 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
227231 pub fn write ( & self ) -> LockResult < RwLockWriteGuard < T > > {
228- unsafe { self . inner . lock . write ( ) }
229- unsafe { RwLockWriteGuard :: new ( & * self . inner , & self . data ) }
232+ unsafe {
233+ self . inner . lock . write ( ) ;
234+ RwLockWriteGuard :: new ( & * self . inner , & self . data )
235+ }
230236 }
231237
232238 /// Attempts to lock this rwlock with exclusive write access.
@@ -249,10 +255,12 @@ impl<T: ?Sized> RwLock<T> {
249255 #[ inline]
250256 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
251257 pub fn try_write ( & self ) -> TryLockResult < RwLockWriteGuard < T > > {
252- if unsafe { self . inner . lock . try_write ( ) } {
253- Ok ( try!( unsafe { RwLockWriteGuard :: new ( & * self . inner , & self . data ) } ) )
254- } else {
255- Err ( TryLockError :: WouldBlock )
258+ unsafe {
259+ if self . inner . lock . try_write ( ) {
260+ Ok ( try!( RwLockWriteGuard :: new ( & * self . inner , & self . data ) ) )
261+ } else {
262+ Err ( TryLockError :: WouldBlock )
263+ }
256264 }
257265 }
258266
@@ -360,8 +368,10 @@ impl StaticRwLock {
360368 /// See `RwLock::read`.
361369 #[ inline]
362370 pub fn read ( & ' static self ) -> LockResult < RwLockReadGuard < ' static , ( ) > > {
363- unsafe { self . lock . read ( ) }
364- unsafe { RwLockReadGuard :: new ( self , & DUMMY . 0 ) }
371+ unsafe {
372+ self . lock . read ( ) ;
373+ RwLockReadGuard :: new ( self , & DUMMY . 0 )
374+ }
365375 }
366376
367377 /// Attempts to acquire this lock with shared read access.
@@ -370,10 +380,12 @@ impl StaticRwLock {
370380 #[ inline]
371381 pub fn try_read ( & ' static self )
372382 -> TryLockResult < RwLockReadGuard < ' static , ( ) > > {
373- if unsafe { self . lock . try_read ( ) } {
374- unsafe { Ok ( try!( RwLockReadGuard :: new ( self , & DUMMY . 0 ) ) ) }
375- } else {
376- Err ( TryLockError :: WouldBlock )
383+ unsafe {
384+ if self . lock . try_read ( ) {
385+ Ok ( try!( RwLockReadGuard :: new ( self , & DUMMY . 0 ) ) )
386+ } else {
387+ Err ( TryLockError :: WouldBlock )
388+ }
377389 }
378390 }
379391
@@ -383,8 +395,10 @@ impl StaticRwLock {
383395 /// See `RwLock::write`.
384396 #[ inline]
385397 pub fn write ( & ' static self ) -> LockResult < RwLockWriteGuard < ' static , ( ) > > {
386- unsafe { self . lock . write ( ) }
387- unsafe { RwLockWriteGuard :: new ( self , & DUMMY . 0 ) }
398+ unsafe {
399+ self . lock . write ( ) ;
400+ RwLockWriteGuard :: new ( self , & DUMMY . 0 )
401+ }
388402 }
389403
390404 /// Attempts to lock this rwlock with exclusive write access.
@@ -393,10 +407,12 @@ impl StaticRwLock {
393407 #[ inline]
394408 pub fn try_write ( & ' static self )
395409 -> TryLockResult < RwLockWriteGuard < ' static , ( ) > > {
396- if unsafe { self . lock . try_write ( ) } {
397- Ok ( unsafe { try!( RwLockWriteGuard :: new ( self , & DUMMY . 0 ) ) } )
398- } else {
399- Err ( TryLockError :: WouldBlock )
410+ unsafe {
411+ if self . lock . try_write ( ) {
412+ Ok ( try!( RwLockWriteGuard :: new ( self , & DUMMY . 0 ) ) )
413+ } else {
414+ Err ( TryLockError :: WouldBlock )
415+ }
400416 }
401417 }
402418
@@ -439,9 +455,10 @@ impl<'rwlock, T: ?Sized> RwLockReadGuard<'rwlock, T> {
439455 /// ```
440456 #[ unstable( feature = "guard_map" ,
441457 reason = "recently added, needs RFC for stabilization" ,
442- issue = "0 " ) ]
458+ issue = "27746 " ) ]
443459 pub fn map < U : ?Sized , F > ( this : Self , cb : F ) -> RwLockReadGuard < ' rwlock , U >
444- where F : FnOnce ( & ' rwlock T ) -> & ' rwlock U {
460+ where F : FnOnce ( & ' rwlock T ) -> & ' rwlock U
461+ {
445462 let new = RwLockReadGuard {
446463 __lock : this. __lock ,
447464 __data : cb ( this. __data )
@@ -478,7 +495,7 @@ impl<'rwlock, T: ?Sized> RwLockWriteGuard<'rwlock, T> {
478495 /// let x = RwLock::new(vec![1, 2]);
479496 ///
480497 /// {
481- /// let y = RwLockWriteGuard::map(x.write().unwrap(), |v| &mut v[0]);
498+ /// let mut y = RwLockWriteGuard::map(x.write().unwrap(), |v| &mut v[0]);
482499 /// assert_eq!(*y, 1);
483500 ///
484501 /// *y = 10;
@@ -488,18 +505,20 @@ impl<'rwlock, T: ?Sized> RwLockWriteGuard<'rwlock, T> {
488505 /// ```
489506 #[ unstable( feature = "guard_map" ,
490507 reason = "recently added, needs RFC for stabilization" ,
491- issue = "0 " ) ]
508+ issue = "27746 " ) ]
492509 pub fn map < U : ?Sized , F > ( this : Self , cb : F ) -> RwLockWriteGuard < ' rwlock , U >
493- where F : FnOnce ( & ' rwlock mut T ) -> & ' rwlock mut U {
510+ where F : FnOnce ( & ' rwlock mut T ) -> & ' rwlock mut U
511+ {
494512 // Compute the new data while still owning the original lock
495513 // in order to correctly poison if the callback panics.
496514 let data = unsafe { ptr:: read ( & this. __data ) } ;
497515 let new_data = cb ( data) ;
498516
499517 // We don't want to unlock the lock by running the destructor of the
500518 // original lock, so just read the fields we need and forget it.
501- let poison = unsafe { ptr:: read ( & this. __poison ) } ;
502- let lock = unsafe { ptr:: read ( & this. __lock ) } ;
519+ let ( poison, lock) = unsafe {
520+ ( ptr:: read ( & this. __poison ) , ptr:: read ( & this. __lock ) )
521+ } ;
503522 mem:: forget ( this) ;
504523
505524 RwLockWriteGuard {
0 commit comments