@@ -537,21 +537,26 @@ impl<Tag: Provenance, Extra> Allocation<Tag, Extra> {
537537/// Relocations.
538538impl < Tag : Copy , Extra > Allocation < Tag , Extra > {
539539 /// 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 ) ] {
541541 // We have to go back `pointer_size - 1` bytes, as that one would still overlap with
542542 // the beginning of this range.
543543 let start = range. start . bytes ( ) . saturating_sub ( cx. data_layout ( ) . pointer_size . bytes ( ) - 1 ) ;
544544 self . relocations . range ( Size :: from_bytes ( start) ..range. end ( ) )
545545 }
546546
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+
547556 /// Checks that there are no relocations overlapping with the given range.
548557 #[ inline( always) ]
549558 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 ( ( ) ) }
555560 }
556561
557562 /// Removes all relocations inside the given range.
0 commit comments