@@ -537,21 +537,26 @@ impl<Tag: Provenance, Extra> Allocation<Tag, Extra> {
537
537
/// Relocations.
538
538
impl < Tag : Copy , Extra > Allocation < Tag , Extra > {
539
539
/// Returns all relocations overlapping with the given pointer-offset pair.
540
- pub fn get_relocations ( & self , cx : & impl HasDataLayout , range : AllocRange ) -> & [ ( Size , Tag ) ] {
540
+ fn get_relocations ( & self , cx : & impl HasDataLayout , range : AllocRange ) -> & [ ( Size , Tag ) ] {
541
541
// We have to go back `pointer_size - 1` bytes, as that one would still overlap with
542
542
// the beginning of this range.
543
543
let start = range. start . bytes ( ) . saturating_sub ( cx. data_layout ( ) . pointer_size . bytes ( ) - 1 ) ;
544
544
self . relocations . range ( Size :: from_bytes ( start) ..range. end ( ) )
545
545
}
546
546
547
+ /// Returns whether this allocation has relocations overlapping with the given range.
548
+ ///
549
+ /// Note: this function exists to allow `get_relocations` to be private, in order to somewhat
550
+ /// limit access to relocations outside of the `Allocation` abstraction.
551
+ ///
552
+ pub fn has_relocations ( & self , cx : & impl HasDataLayout , range : AllocRange ) -> bool {
553
+ !self . get_relocations ( cx, range) . is_empty ( )
554
+ }
555
+
547
556
/// Checks that there are no relocations overlapping with the given range.
548
557
#[ inline( always) ]
549
558
fn check_relocations ( & self , cx : & impl HasDataLayout , range : AllocRange ) -> AllocResult {
550
- if self . get_relocations ( cx, range) . is_empty ( ) {
551
- Ok ( ( ) )
552
- } else {
553
- Err ( AllocError :: ReadPointerAsBytes )
554
- }
559
+ if self . has_relocations ( cx, range) { Err ( AllocError :: ReadPointerAsBytes ) } else { Ok ( ( ) ) }
555
560
}
556
561
557
562
/// Removes all relocations inside the given range.
0 commit comments