@@ -720,26 +720,6 @@ impl<'a, T: 'a, A: Alloc> Vec<'a, T, A> {
720720 self . buf . set_len ( new_len) ;
721721 }
722722
723- /// Returns a shared reference to the allocator backing this `Vec`.
724- ///
725- /// # Examples
726- ///
727- /// ```
728- /// use bumpalo::{Bump, collections::Vec};
729- ///
730- /// // uses the same allocator as the provided `Vec`
731- /// fn add_strings<'a>(vec: &mut Vec<'a, &'a str>) {
732- /// for string in ["foo", "bar", "baz"] {
733- /// vec.push(vec.bump().alloc_str(string));
734- /// }
735- /// }
736- /// ```
737- #[ inline]
738- #[ must_use]
739- pub fn bump ( & self ) -> & ' a A {
740- self . buf . bump ( )
741- }
742-
743723 /// Reserves capacity for at least `additional` more elements to be inserted
744724 /// in the given `Vec<'a, T>`. The collection may reserve more space to avoid
745725 /// frequent reallocations. After calling `reserve`, capacity will be
@@ -1735,7 +1715,10 @@ impl<'a, T: 'a, A: Alloc> Vec<'a, T, A> {
17351715 assert ! ( at <= self . len_usize( ) , "`at` out of bounds" ) ;
17361716
17371717 let other_len = self . len_usize ( ) - at;
1738- let mut other = Vec :: with_capacity_in ( other_len, self . buf . bump ( ) ) ;
1718+ // SAFETY: This method takes a `&mut self`. It lives for the duration of this method
1719+ // - longer than we use `bump` for.
1720+ let bump = unsafe { self . buf . bump ( ) } ;
1721+ let mut other = Vec :: with_capacity_in ( other_len, bump) ;
17391722
17401723 // Unsafely `set_len` and copy items to `other`.
17411724 unsafe {
@@ -2683,7 +2666,15 @@ impl<I: Iterator, A: Alloc> Drop for Splice<'_, '_, I, A> {
26832666
26842667 // Collect any remaining elements.
26852668 // This is a zero-length vector which does not allocate if `lower_bound` was exact.
2686- let mut collected = Vec :: new_in ( self . drain . vec . as_ref ( ) . buf . bump ( ) ) ;
2669+
2670+ // SAFETY: `Splice` iterator is created in `Vec::splice`, which takes a `&mut self`.
2671+ // `Splice` inherits the lifetime of `&mut self` from that method, so the mut borrow
2672+ // of the `Vec` is held for the life of the `Splice`.
2673+ // Therefore we have exclusive access to the `Vec` until end of this method.
2674+ // That is longer than we use `bump` for.
2675+ let bump = self . drain . vec . as_ref ( ) . buf . bump ( ) ;
2676+
2677+ let mut collected = Vec :: new_in ( bump) ;
26872678 collected. extend ( self . replace_with . by_ref ( ) ) ;
26882679 let mut collected = collected. into_iter ( ) ;
26892680 // Now we have an exact count.
0 commit comments