@@ -33,8 +33,12 @@ pub unsafe trait RawData: Sized {
3333
3434 #[ doc( hidden) ]
3535 // This method is only used for debugging
36+ #[ deprecated( note="Unused" , since="0.15.2" ) ]
3637 fn _data_slice ( & self ) -> Option < & [ Self :: Elem ] > ;
3738
39+ #[ doc( hidden) ]
40+ fn _is_pointer_inbounds ( & self , ptr : * const Self :: Elem ) -> bool ;
41+
3842 private_decl ! { }
3943}
4044
@@ -146,9 +150,15 @@ pub unsafe trait DataMut: Data + RawDataMut {
146150
147151unsafe impl < A > RawData for RawViewRepr < * const A > {
148152 type Elem = A ;
153+
154+ #[ inline]
149155 fn _data_slice ( & self ) -> Option < & [ A ] > {
150156 None
151157 }
158+
159+ #[ inline]
160+ fn _is_pointer_inbounds ( & self , _ptr : * const Self :: Elem ) -> bool { true }
161+
152162 private_impl ! { }
153163}
154164
@@ -160,9 +170,15 @@ unsafe impl<A> RawDataClone for RawViewRepr<*const A> {
160170
161171unsafe impl < A > RawData for RawViewRepr < * mut A > {
162172 type Elem = A ;
173+
174+ #[ inline]
163175 fn _data_slice ( & self ) -> Option < & [ A ] > {
164176 None
165177 }
178+
179+ #[ inline]
180+ fn _is_pointer_inbounds ( & self , _ptr : * const Self :: Elem ) -> bool { true }
181+
166182 private_impl ! { }
167183}
168184
@@ -192,6 +208,11 @@ unsafe impl<A> RawData for OwnedArcRepr<A> {
192208 fn _data_slice ( & self ) -> Option < & [ A ] > {
193209 Some ( self . 0 . as_slice ( ) )
194210 }
211+
212+ fn _is_pointer_inbounds ( & self , self_ptr : * const Self :: Elem ) -> bool {
213+ self . 0 . _is_pointer_inbounds ( self_ptr)
214+ }
215+
195216 private_impl ! { }
196217}
197218
@@ -274,9 +295,18 @@ unsafe impl<A> RawDataClone for OwnedArcRepr<A> {
274295
275296unsafe impl < A > RawData for OwnedRepr < A > {
276297 type Elem = A ;
298+
277299 fn _data_slice ( & self ) -> Option < & [ A ] > {
278300 Some ( self . as_slice ( ) )
279301 }
302+
303+ fn _is_pointer_inbounds ( & self , self_ptr : * const Self :: Elem ) -> bool {
304+ let slc = self . as_slice ( ) ;
305+ let ptr = slc. as_ptr ( ) as * mut A ;
306+ let end = unsafe { ptr. add ( slc. len ( ) ) } ;
307+ self_ptr >= ptr && self_ptr <= end
308+ }
309+
280310 private_impl ! { }
281311}
282312
@@ -340,9 +370,15 @@ where
340370
341371unsafe impl < ' a , A > RawData for ViewRepr < & ' a A > {
342372 type Elem = A ;
373+
374+ #[ inline]
343375 fn _data_slice ( & self ) -> Option < & [ A ] > {
344376 None
345377 }
378+
379+ #[ inline]
380+ fn _is_pointer_inbounds ( & self , _ptr : * const Self :: Elem ) -> bool { true }
381+
346382 private_impl ! { }
347383}
348384
@@ -364,9 +400,15 @@ unsafe impl<'a, A> RawDataClone for ViewRepr<&'a A> {
364400
365401unsafe impl < ' a , A > RawData for ViewRepr < & ' a mut A > {
366402 type Elem = A ;
403+
404+ #[ inline]
367405 fn _data_slice ( & self ) -> Option < & [ A ] > {
368406 None
369407 }
408+
409+ #[ inline]
410+ fn _is_pointer_inbounds ( & self , _ptr : * const Self :: Elem ) -> bool { true }
411+
370412 private_impl ! { }
371413}
372414
@@ -458,12 +500,22 @@ unsafe impl<A> DataOwned for OwnedArcRepr<A> {
458500
459501unsafe impl < ' a , A > RawData for CowRepr < ' a , A > {
460502 type Elem = A ;
503+
461504 fn _data_slice ( & self ) -> Option < & [ A ] > {
505+ #[ allow( deprecated) ]
462506 match self {
463507 CowRepr :: View ( view) => view. _data_slice ( ) ,
464508 CowRepr :: Owned ( data) => data. _data_slice ( ) ,
465509 }
466510 }
511+
512+ fn _is_pointer_inbounds ( & self , ptr : * const Self :: Elem ) -> bool {
513+ match self {
514+ CowRepr :: View ( view) => view. _is_pointer_inbounds ( ptr) ,
515+ CowRepr :: Owned ( data) => data. _is_pointer_inbounds ( ptr) ,
516+ }
517+ }
518+
467519 private_impl ! { }
468520}
469521
0 commit comments