13
13
use cast;
14
14
use libc;
15
15
use libc:: { c_void, size_t} ;
16
- use option:: { Option , Some , None } ;
17
16
use sys;
18
17
19
18
#[ cfg( not( test) ) ] use cmp:: { Eq , Ord } ;
@@ -210,7 +209,6 @@ pub unsafe fn array_each<T>(arr: **T, cb: &fn(*T)) {
210
209
pub trait Ptr < T > {
211
210
fn is_null ( & const self ) -> bool ;
212
211
fn is_not_null ( & const self ) -> bool ;
213
- unsafe fn to_option ( & const self ) -> Option < & T > ;
214
212
fn offset ( & self , count : uint ) -> Self ;
215
213
}
216
214
@@ -224,23 +222,6 @@ impl<T> Ptr<T> for *T {
224
222
#[ inline( always) ]
225
223
fn is_not_null ( & const self ) -> bool { is_not_null ( * self ) }
226
224
227
- ///
228
- /// Returns `None` if the pointer is null, or else returns the value wrapped
229
- /// in `Some`.
230
- ///
231
- /// # Safety Notes
232
- ///
233
- /// While this method is useful for null-safety, it is important to note
234
- /// that this is still an unsafe operation because the returned value could
235
- /// be pointing to invalid memory.
236
- ///
237
- #[ inline( always) ]
238
- unsafe fn to_option ( & const self ) -> Option < & T > {
239
- if self . is_null ( ) { None } else {
240
- Some ( cast:: transmute ( * self ) )
241
- }
242
- }
243
-
244
225
/// Calculates the offset from a pointer.
245
226
#[ inline( always) ]
246
227
fn offset ( & self , count : uint ) -> * T { offset ( * self , count) }
@@ -256,23 +237,6 @@ impl<T> Ptr<T> for *mut T {
256
237
#[ inline( always) ]
257
238
fn is_not_null ( & const self ) -> bool { is_not_null ( * self ) }
258
239
259
- ///
260
- /// Returns `None` if the pointer is null, or else returns the value wrapped
261
- /// in `Some`.
262
- ///
263
- /// # Safety Notes
264
- ///
265
- /// While this method is useful for null-safety, it is important to note
266
- /// that this is still an unsafe operation because the returned value could
267
- /// be pointing to invalid memory.
268
- ///
269
- #[ inline( always) ]
270
- unsafe fn to_option ( & const self ) -> Option < & T > {
271
- if self . is_null ( ) { None } else {
272
- Some ( cast:: transmute ( * self ) )
273
- }
274
- }
275
-
276
240
/// Calculates the offset from a mutable pointer.
277
241
#[ inline( always) ]
278
242
fn offset ( & self , count : uint ) -> * mut T { mut_offset ( * self , count) }
@@ -459,21 +423,6 @@ pub mod ptr_tests {
459
423
assert ! ( mq. is_not_null( ) ) ;
460
424
}
461
425
462
- #[ test]
463
- fn test_to_option ( ) {
464
- let p: * int = null ( ) ;
465
- // FIXME (#6641): Usage of unsafe methods in safe code doesn't cause an error.
466
- assert_eq ! ( p. to_option( ) , None ) ;
467
-
468
- let q: * int = & 2 ;
469
- assert_eq ! ( q. to_option( ) . unwrap( ) , & 2 ) ; // FIXME (#6641)
470
-
471
- let p: * mut int = mut_null ( ) ;
472
- assert_eq ! ( p. to_option( ) , None ) ; // FIXME (#6641)
473
-
474
- let q: * mut int = & mut 2 ;
475
- assert_eq ! ( q. to_option( ) . unwrap( ) , & 2 ) ; // FIXME (#6641)
476
- }
477
426
478
427
#[ test]
479
428
fn test_ptr_array_each_with_len ( ) {
0 commit comments