@@ -127,40 +127,12 @@ where
127127 F : FnOnce ( T ) ,
128128{
129129 fn drop ( & mut self ) {
130- // SAFETY: we're taking the values out of the `ManuallyDrop` with
131- // the express intent of dropping them.
130+ // SAFETY: `DropGuard` is in the process of being dropped.
132131 let inner = unsafe { ManuallyDrop :: take ( & mut self . inner ) } ;
133- let f = unsafe { ManuallyDrop :: take ( & mut self . f ) } ;
134- f ( inner) ;
135- }
136- }
137132
138- // tests copied from https://docs.rs/scopeguard/latest/src/scopeguard/lib.rs.html#1-595
139- #[ cfg( test) ]
140- mod tests {
141- use super :: * ;
142- use crate :: cell:: Cell ;
143-
144- #[ test]
145- fn test_only_dropped_by_closure_when_run ( ) {
146- let value_drops = Cell :: new ( 0 ) ;
147- let value = DropGuard :: new ( ( ) , |( ) | value_drops. set ( 1 + value_drops. get ( ) ) ) ;
148- let closure_drops = Cell :: new ( 0 ) ;
149- let guard = DropGuard :: new ( value, |_| closure_drops. set ( 1 + closure_drops. get ( ) ) ) ;
150- assert_eq ! ( value_drops. get( ) , 0 ) ;
151- assert_eq ! ( closure_drops. get( ) , 0 ) ;
152- drop ( guard) ;
153- assert_eq ! ( value_drops. get( ) , 1 ) ;
154- assert_eq ! ( closure_drops. get( ) , 1 ) ;
155- }
133+ // SAFETY: `DropGuard` is in the process of being dropped.
134+ let f = unsafe { ManuallyDrop :: take ( & mut self . f ) } ;
156135
157- #[ test]
158- fn test_into_inner ( ) {
159- let dropped = Cell :: new ( false ) ;
160- let value = DropGuard :: new ( 42 , |_| dropped. set ( true ) ) ;
161- let guard = DropGuard :: new ( value, |_| dropped. set ( true ) ) ;
162- let inner = DropGuard :: into_inner ( guard) ;
163- assert_eq ! ( dropped. get( ) , false ) ;
164- assert_eq ! ( * inner, 42 ) ;
136+ f ( inner) ;
165137 }
166138}
0 commit comments