File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1803,9 +1803,32 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1803
1803
}
1804
1804
1805
1805
/// Returns a pointer to a control byte.
1806
+ ///
1807
+ /// # Safety
1808
+ ///
1809
+ /// For the allocated [`RawTableInner`], the result is [`Undefined Behavior`],
1810
+ /// if the `index` is greater than the `self.bucket_mask + 1 + Group::WIDTH`.
1811
+ /// In that case, calling this function with `index == self.bucket_mask + 1 + Group::WIDTH`
1812
+ /// will return a pointer to the end of the allocated table and it is useless on its own.
1813
+ ///
1814
+ /// Calling this function with `index >= self.bucket_mask + 1 + Group::WIDTH` on a
1815
+ /// table that has not been allocated results in [`Undefined Behavior`].
1816
+ ///
1817
+ /// So to satisfy both requirements you should always follow the rule that
1818
+ /// `index < self.bucket_mask + 1 + Group::WIDTH`
1819
+ ///
1820
+ /// Calling this function on [`RawTableInner`] that are not already allocated is safe
1821
+ /// for read-only purpose.
1822
+ ///
1823
+ /// See also [`Bucket::as_ptr()`] method, for more information about of properly removing
1824
+ /// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`].
1825
+ ///
1826
+ /// [`Bucket::as_ptr()`]: Bucket::as_ptr()
1827
+ /// [`Undefined Behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
1806
1828
#[ inline]
1807
1829
unsafe fn ctrl ( & self , index : usize ) -> * mut u8 {
1808
1830
debug_assert ! ( index < self . num_ctrl_bytes( ) ) ;
1831
+ // SAFETY: The caller must uphold the safety rules for the [`RawTableInner::ctrl`]
1809
1832
self . ctrl . as_ptr ( ) . add ( index)
1810
1833
}
1811
1834
You can’t perform that action at this time.
0 commit comments