@@ -272,7 +272,6 @@ pub trait RawPtr<T> {
272
272
fn is_not_null ( & self ) -> bool ;
273
273
unsafe fn to_option ( & self ) -> Option < & T > ;
274
274
fn offset ( & self , count : int ) -> Self ;
275
- #[ cfg( not( stage0) ) ]
276
275
unsafe fn offset_inbounds ( self , count : int ) -> Self ;
277
276
}
278
277
@@ -307,6 +306,14 @@ impl<T> RawPtr<T> for *T {
307
306
#[ inline]
308
307
fn offset ( & self , count : int ) -> * T { offset ( * self , count) }
309
308
309
+ /// Calculates the offset from a pointer. The offset *must* be in-bounds of
310
+ /// the object, or one-byte-past-the-end.
311
+ #[ inline]
312
+ #[ cfg( stage0) ]
313
+ unsafe fn offset_inbounds ( self , count : int ) -> * T {
314
+ intrinsics:: offset ( self , count)
315
+ }
316
+
310
317
/// Calculates the offset from a pointer. The offset *must* be in-bounds of
311
318
/// the object, or one-byte-past-the-end.
312
319
#[ inline]
@@ -347,6 +354,18 @@ impl<T> RawPtr<T> for *mut T {
347
354
#[ inline]
348
355
fn offset ( & self , count : int ) -> * mut T { mut_offset ( * self , count) }
349
356
357
+ /// Calculates the offset from a pointer. The offset *must* be in-bounds of
358
+ /// the object, or one-byte-past-the-end. An arithmetic overflow is also
359
+ /// undefined behaviour.
360
+ ///
361
+ /// This method should be preferred over `offset` when the guarantee can be
362
+ /// satisfied, to enable better optimization.
363
+ #[ inline]
364
+ #[ cfg( stage0) ]
365
+ unsafe fn offset_inbounds ( self , count : int ) -> * mut T {
366
+ intrinsics:: offset ( self as * T , count) as * mut T
367
+ }
368
+
350
369
/// Calculates the offset from a pointer. The offset *must* be in-bounds of
351
370
/// the object, or one-byte-past-the-end. An arithmetic overflow is also
352
371
/// undefined behaviour.
0 commit comments