Skip to content

Commit 1f15c2a

Browse files
committed
Merge ref '36e4f5d1fe1d' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: 36e4f5d Filtered ref: ebb8df69f0a82b8a19e4f4b3cd32436022de4fa0 Upstream diff: rust-lang/rust@4fd3181...36e4f5d This merge was created using https://github.com/rust-lang/josh-sync.
2 parents 59844f2 + 096629e commit 1f15c2a

File tree

23 files changed

+402
-289
lines changed

23 files changed

+402
-289
lines changed

alloc/src/collections/btree/map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,8 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
13681368
}
13691369

13701370
/// Splits the collection into two at the given key. Returns everything after the given key,
1371-
/// including the key.
1371+
/// including the key. If the key is not present, the split will occur at the nearest
1372+
/// greater key, or return an empty map if no such key exists.
13721373
///
13731374
/// # Examples
13741375
///

alloc/src/raw_vec/mod.rs

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,7 @@ impl<A: Allocator> RawVecInner<A> {
668668
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
669669
/// initially construct `self`
670670
/// - `elem_layout`'s size must be a multiple of its alignment
671-
/// - The sum of `len` and `additional` must be greater than or equal to
672-
/// `self.capacity(elem_layout.size())`
671+
/// - The sum of `len` and `additional` must be greater than the current capacity
673672
unsafe fn grow_amortized(
674673
&mut self,
675674
len: usize,
@@ -693,16 +692,12 @@ impl<A: Allocator> RawVecInner<A> {
693692
let cap = cmp::max(self.cap.as_inner() * 2, required_cap);
694693
let cap = cmp::max(min_non_zero_cap(elem_layout.size()), cap);
695694

696-
let new_layout = layout_array(cap, elem_layout)?;
697-
698695
// SAFETY:
699-
// - For the `current_memory` call: Precondition passed to caller
700-
// - For the `finish_grow` call: Precondition passed to caller
701-
// + `current_memory` does the right thing
702-
let ptr =
703-
unsafe { finish_grow(new_layout, self.current_memory(elem_layout), &mut self.alloc)? };
696+
// - cap >= len + additional
697+
// - other preconditions passed to caller
698+
let ptr = unsafe { self.finish_grow(cap, elem_layout)? };
704699

705-
// SAFETY: layout_array would have resulted in a capacity overflow if we tried to allocate more than `isize::MAX` items
700+
// SAFETY: `finish_grow` would have failed if `cap > isize::MAX`
706701
unsafe { self.set_ptr_and_cap(ptr, cap) };
707702
Ok(())
708703
}
@@ -711,8 +706,7 @@ impl<A: Allocator> RawVecInner<A> {
711706
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
712707
/// initially construct `self`
713708
/// - `elem_layout`'s size must be a multiple of its alignment
714-
/// - The sum of `len` and `additional` must be greater than or equal to
715-
/// `self.capacity(elem_layout.size())`
709+
/// - The sum of `len` and `additional` must be greater than the current capacity
716710
unsafe fn grow_exact(
717711
&mut self,
718712
len: usize,
@@ -726,21 +720,44 @@ impl<A: Allocator> RawVecInner<A> {
726720
}
727721

728722
let cap = len.checked_add(additional).ok_or(CapacityOverflow)?;
729-
let new_layout = layout_array(cap, elem_layout)?;
730723

731-
// SAFETY:
732-
// - For the `current_memory` call: Precondition passed to caller
733-
// - For the `finish_grow` call: Precondition passed to caller
734-
// + `current_memory` does the right thing
735-
let ptr =
736-
unsafe { finish_grow(new_layout, self.current_memory(elem_layout), &mut self.alloc)? };
737-
// SAFETY: layout_array would have resulted in a capacity overflow if we tried to allocate more than `isize::MAX` items
738-
unsafe {
739-
self.set_ptr_and_cap(ptr, cap);
740-
}
724+
// SAFETY: preconditions passed to caller
725+
let ptr = unsafe { self.finish_grow(cap, elem_layout)? };
726+
727+
// SAFETY: `finish_grow` would have failed if `cap > isize::MAX`
728+
unsafe { self.set_ptr_and_cap(ptr, cap) };
741729
Ok(())
742730
}
743731

732+
/// # Safety
733+
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
734+
/// initially construct `self`
735+
/// - `elem_layout`'s size must be a multiple of its alignment
736+
/// - `cap` must be greater than the current capacity
737+
// not marked inline(never) since we want optimizers to be able to observe the specifics of this
738+
// function, see tests/codegen-llvm/vec-reserve-extend.rs.
739+
#[cold]
740+
unsafe fn finish_grow(
741+
&self,
742+
cap: usize,
743+
elem_layout: Layout,
744+
) -> Result<NonNull<[u8]>, TryReserveError> {
745+
let new_layout = layout_array(cap, elem_layout)?;
746+
747+
let memory = if let Some((ptr, old_layout)) = unsafe { self.current_memory(elem_layout) } {
748+
debug_assert_eq!(old_layout.align(), new_layout.align());
749+
unsafe {
750+
// The allocator checks for alignment equality
751+
hint::assert_unchecked(old_layout.align() == new_layout.align());
752+
self.alloc.grow(ptr, old_layout, new_layout)
753+
}
754+
} else {
755+
self.alloc.allocate(new_layout)
756+
};
757+
758+
memory.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () }.into())
759+
}
760+
744761
/// # Safety
745762
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
746763
/// initially construct `self`
@@ -820,38 +837,6 @@ impl<A: Allocator> RawVecInner<A> {
820837
}
821838
}
822839

823-
/// # Safety
824-
/// If `current_memory` matches `Some((ptr, old_layout))`:
825-
/// - `ptr` must denote a block of memory *currently allocated* via `alloc`
826-
/// - `old_layout` must *fit* that block of memory
827-
/// - `new_layout` must have the same alignment as `old_layout`
828-
/// - `new_layout.size()` must be greater than or equal to `old_layout.size()`
829-
/// If `current_memory` is `None`, this function is safe.
830-
// not marked inline(never) since we want optimizers to be able to observe the specifics of this
831-
// function, see tests/codegen-llvm/vec-reserve-extend.rs.
832-
#[cold]
833-
unsafe fn finish_grow<A>(
834-
new_layout: Layout,
835-
current_memory: Option<(NonNull<u8>, Layout)>,
836-
alloc: &mut A,
837-
) -> Result<NonNull<[u8]>, TryReserveError>
838-
where
839-
A: Allocator,
840-
{
841-
let memory = if let Some((ptr, old_layout)) = current_memory {
842-
debug_assert_eq!(old_layout.align(), new_layout.align());
843-
unsafe {
844-
// The allocator checks for alignment equality
845-
hint::assert_unchecked(old_layout.align() == new_layout.align());
846-
alloc.grow(ptr, old_layout, new_layout)
847-
}
848-
} else {
849-
alloc.allocate(new_layout)
850-
};
851-
852-
memory.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () }.into())
853-
}
854-
855840
// Central function for reserve error handling.
856841
#[cfg(not(no_global_oom_handling))]
857842
#[cold]

core/src/intrinsics/mir.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@
227227
//!
228228
//! #### Statements
229229
//! - Assign statements work via normal Rust assignment.
230-
//! - [`Retag`], [`StorageLive`], [`StorageDead`], [`Deinit`] statements have an associated function.
230+
//! - [`Retag`], [`StorageLive`], [`StorageDead`] statements have an associated function.
231231
//!
232232
//! #### Rvalues
233233
//!
234234
//! - Operands implicitly convert to `Use` rvalues.
235235
//! - `&`, `&mut`, `addr_of!`, and `addr_of_mut!` all work to create their associated rvalue.
236-
//! - [`CopyForDeref`], [`CastTransmute`], [`CastPtrToPtr`], [`CastUnsize`], and [`Discriminant`]
236+
//! - [`CastTransmute`], [`CastPtrToPtr`], [`CastUnsize`], and [`Discriminant`]
237237
//! have associated functions.
238238
//! - Unary and binary operations use their normal Rust syntax - `a * b`, `!c`, etc.
239239
//! - The binary operation `Offset` can be created via [`Offset`].
@@ -400,13 +400,11 @@ define!("mir_unwind_resume",
400400
define!("mir_storage_live", fn StorageLive<T>(local: T));
401401
define!("mir_storage_dead", fn StorageDead<T>(local: T));
402402
define!("mir_assume", fn Assume(operand: bool));
403-
define!("mir_deinit", fn Deinit<T>(place: T));
404403
define!("mir_checked", fn Checked<T>(binop: T) -> (T, bool));
405404
define!(
406405
"mir_ptr_metadata",
407406
fn PtrMetadata<P: ?Sized>(place: *const P) -> <P as ::core::ptr::Pointee>::Metadata
408407
);
409-
define!("mir_copy_for_deref", fn CopyForDeref<T>(place: T) -> T);
410408
define!("mir_retag", fn Retag<T>(place: T));
411409
define!("mir_move", fn Move<T>(place: T) -> T);
412410
define!("mir_static", fn Static<T>(s: T) -> &'static T);

core/src/iter/sources/repeat.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ use crate::num::NonZero;
88
/// Infinite iterators like `repeat()` are often used with adapters like
99
/// [`Iterator::take()`], in order to make them finite.
1010
///
11+
/// If you know the number of repetitions in advance, consider using [`repeat_n()`]
12+
/// instead, as it is more efficient and conveys the intent more clearly.
13+
///
1114
/// Use [`str::repeat()`] instead of this function if you just want to repeat
1215
/// a char/string `n` times.
1316
///
1417
/// If the element type of the iterator you need does not implement `Clone`,
1518
/// or if you do not want to keep the repeated element in memory, you can
1619
/// instead use the [`repeat_with()`] function.
1720
///
21+
/// [`repeat_n()`]: crate::iter::repeat_n
1822
/// [`repeat_with()`]: crate::iter::repeat_with
1923
/// [`str::repeat()`]: ../../std/primitive.str.html#method.repeat
2024
///

0 commit comments

Comments
 (0)