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 @@ -1342,9 +1342,32 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1342
1342
}
1343
1343
1344
1344
/// Returns a pointer to a control byte.
1345
+ ///
1346
+ /// # Safety
1347
+ ///
1348
+ /// For the allocated [`RawTableInner`], the result is [`Undefined Behavior`],
1349
+ /// if the `index` is greater than the `self.bucket_mask + 1 + Group::WIDTH`.
1350
+ /// In that case, calling this function with `index == self.bucket_mask + 1 + Group::WIDTH`
1351
+ /// will return a pointer to the end of the allocated table and it is useless on its own.
1352
+ ///
1353
+ /// Calling this function with `index >= self.bucket_mask + 1 + Group::WIDTH` on a
1354
+ /// table that has not been allocated results in [`Undefined Behavior`].
1355
+ ///
1356
+ /// So to satisfy both requirements you should always follow the rule that
1357
+ /// `index < self.bucket_mask + 1 + Group::WIDTH`
1358
+ ///
1359
+ /// Calling this function on [`RawTableInner`] that are not already allocated if safe
1360
+ /// for read-only purpose.
1361
+ ///
1362
+ /// See also [`Bucket::as_ptr()`] method, for more information about of properly removing
1363
+ /// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`].
1364
+ ///
1365
+ /// [`Bucket::as_ptr()`]: Bucket::as_ptr()
1366
+ /// [`Undefined Behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
1345
1367
#[ inline]
1346
1368
unsafe fn ctrl ( & self , index : usize ) -> * mut u8 {
1347
1369
debug_assert ! ( index < self . num_ctrl_bytes( ) ) ;
1370
+ // SAFETY: The caller must uphold the safety rules for the [`RawTableInner::ctrl`]
1348
1371
self . ctrl . as_ptr ( ) . add ( index)
1349
1372
}
1350
1373
You can’t perform that action at this time.
0 commit comments