From 3847e14ebf395b4dd22927ca754188d8d8c2a71d Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 12 Dec 2022 14:19:28 -0800 Subject: [PATCH] Clean up: Applied x test tidy --bless. NOT COMPILABLE --- compiler/rustc_middle/src/mir/mod.rs | 2 +- compiler/rustc_middle/src/mir/syntax.rs | 2 +- .../rustc_parse/src/parser/attr_wrapper.rs | 2 +- compiler/rustc_parse/src/parser/mod.rs | 7 +- library/alloc/src/boxed.rs | 34 ++- library/alloc/src/collections/binary_heap.rs | 12 +- .../alloc/src/collections/vec_deque/drain.rs | 77 ++++-- .../src/collections/vec_deque/into_iter.rs | 41 +++- .../alloc/src/collections/vec_deque/mod.rs | 154 ++++++++---- .../src/collections/vec_deque/spec_extend.rs | 35 ++- .../collections/vec_deque/spec_from_iter.rs | 19 +- library/alloc/src/raw_vec.rs | 65 +++-- library/alloc/src/slice.rs | 62 +++-- library/alloc/src/vec/drain.rs | 90 +++++-- library/alloc/src/vec/drain_filter.rs | 23 +- library/alloc/src/vec/into_iter.rs | 123 +++++++--- library/alloc/src/vec/mod.rs | 230 +++++++++++++----- library/alloc/src/vec/spec_extend.rs | 23 +- library/alloc/src/vec/spec_from_elem.rs | 51 +++- library/alloc/src/vec/splice.rs | 29 ++- library/alloc/tests/boxed.rs | 2 +- library/core/src/alloc/global.rs | 12 +- library/core/src/alloc/mod.rs | 33 +-- library/std/src/io/cursor.rs | 26 +- library/std/src/io/impls.rs | 12 +- library/std/src/sys/unix/thread_local_dtor.rs | 4 +- src/librustdoc/html/render/context.rs | 5 +- 27 files changed, 828 insertions(+), 347 deletions(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 8b960fa337c45..b1642baeb19e9 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2,7 +2,6 @@ //! //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/mir/index.html -use core::alloc::GlobalCoAllocMeta; use crate::mir::interpret::{ AllocRange, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, LitToConstInput, Scalar, }; @@ -14,6 +13,7 @@ use crate::ty::visit::{TypeVisitable, TypeVisitor}; use crate::ty::{self, DefIdTree, List, Ty, TyCtxt}; use crate::ty::{AdtDef, InstanceDef, ScalarInt, UserTypeAnnotationIndex}; use crate::ty::{GenericArg, InternalSubsts, SubstsRef}; +use core::alloc::GlobalCoAllocMeta; use rustc_data_structures::captures::Captures; use rustc_errors::ErrorGuaranteed; diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 7292ca87ae879..251cb92e10fdb 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -3,9 +3,9 @@ //! This is in a dedicated file so that changes to this file can be reviewed more carefully. //! The intention is that this file only contains datatype declarations, no code. +use super::{BasicBlock, Constant, Field, Local, SwitchTargets, UserTypeProjection}; use core::alloc::GlobalCoAllocMeta; use core::mem; -use super::{BasicBlock, Constant, Field, Local, SwitchTargets, UserTypeProjection}; use crate::mir::coverage::{CodeRegion, CoverageKind}; use crate::traits::Reveal; diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index a8c2d8c2c59d3..df02751005ce8 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -1,6 +1,6 @@ +use super::{Capturing, FlatToken, ForceCollect, Parser, ReplaceRange, TokenCursor, TrailingToken}; use core::alloc::GlobalCoAllocMeta; use core::mem; -use super::{Capturing, FlatToken, ForceCollect, Parser, ReplaceRange, TokenCursor, TrailingToken}; use rustc_ast::token::{self, Delimiter, Token, TokenKind}; use rustc_ast::tokenstream::{AttrTokenStream, AttributesData, ToAttrTokenStream}; use rustc_ast::tokenstream::{AttrTokenTree, DelimSpan, LazyAttrTokenStream, Spacing}; diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 5af17b99b61d9..d6404f46d7268 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -11,8 +11,8 @@ mod stmt; mod ty; use crate::lexer::UnmatchedBrace; -use core::alloc::GlobalCoAllocMeta; pub use attr_wrapper::AttrWrapper; +use core::alloc::GlobalCoAllocMeta; pub use diagnostics::AttemptLocalParseRecovery; pub(crate) use item::FnParseMode; pub use pat::{CommaRecoveryMode, RecoverColon, RecoverComma}; @@ -169,7 +169,10 @@ pub struct Parser<'a> { // This type is used a lot, e.g. it's cloned when matching many declarative macro rules with nonterminals. Make sure // it doesn't unintentionally get bigger. #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(Parser<'_>, 336 + 4 * mem::size_of::()); +rustc_data_structures::static_assert_size!( + Parser<'_>, + 336 + 4 * mem::size_of::() +); /// Stores span information about a closure. #[derive(Clone)] diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 057b46efce69a..b568ece63321c 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -700,7 +700,12 @@ impl Box<[T]> { Err(_) => return Err(AllocError), }; let ptr = Global.allocate(layout)?; - Ok(RawVec::::from_raw_parts_in(ptr.as_mut_ptr() as *mut _, len, Global).into_box(len)) + Ok(RawVec::::from_raw_parts_in( + ptr.as_mut_ptr() as *mut _, + len, + Global, + ) + .into_box(len)) } } @@ -732,13 +737,20 @@ impl Box<[T]> { Err(_) => return Err(AllocError), }; let ptr = Global.allocate_zeroed(layout)?; - Ok(RawVec::::from_raw_parts_in(ptr.as_mut_ptr() as *mut _, len, Global).into_box(len)) + Ok(RawVec::::from_raw_parts_in( + ptr.as_mut_ptr() as *mut _, + len, + Global, + ) + .into_box(len)) } } } impl Box<[T], A> -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +where + [(); core::alloc::co_alloc_metadata_num_slots::()]:, +{ /// Constructs a new boxed slice with uninitialized contents in the provided allocator. /// /// # Examples @@ -766,7 +778,10 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { // #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { - unsafe { RawVec::::with_capacity_in(len, alloc).into_box(len) } + unsafe { + RawVec::::with_capacity_in(len, alloc) + .into_box(len) + } } /// Constructs a new boxed slice with uninitialized contents in the provided allocator, @@ -794,7 +809,12 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { // #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { - unsafe { RawVec::::with_capacity_zeroed_in(len, alloc).into_box(len) } + unsafe { + RawVec::::with_capacity_zeroed_in( + len, alloc, + ) + .into_box(len) + } } } @@ -2052,7 +2072,9 @@ impl FromIterator for Box<[I]> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "box_slice_clone", since = "1.3.0")] impl Clone for Box<[T], A> -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +where + [(); core::alloc::co_alloc_metadata_num_slots::()]:, +{ fn clone(&self) -> Self { let alloc = Box::allocator(self).clone(); self.to_vec_in(alloc).into_boxed_slice() diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 90a952dc0df63..ca22e83b1a69c 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -143,11 +143,11 @@ #![allow(missing_docs)] #![stable(feature = "rust1", since = "1.0.0")] -use core::{alloc, fmt}; use core::iter::{FromIterator, FusedIterator, InPlaceIterable, SourceIter, TrustedLen}; use core::mem::{self, swap, ManuallyDrop}; use core::ops::{Deref, DerefMut}; use core::ptr; +use core::{alloc, fmt}; use crate::alloc::Global; @@ -1198,7 +1198,7 @@ impl BinaryHeap { /// ``` #[inline] #[stable(feature = "drain", since = "1.6.0")] - pub fn drain(&mut self) -> Drain<'_, T, {alloc::SHORT_TERM_VEC_PREFERS_COOP}> { + pub fn drain(&mut self) -> Drain<'_, T, { alloc::SHORT_TERM_VEC_PREFERS_COOP }> { Drain { iter: self.data.drain(..) } } @@ -1479,13 +1479,17 @@ unsafe impl TrustedLen for IntoIterSorted {} #[stable(feature = "drain", since = "1.6.0")] #[derive(Debug)] pub struct Drain<'a, T: 'a, const COOP_PREFERRED: bool> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ iter: vec::Drain<'a, T, Global, COOP_PREFERRED>, } #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_, T, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = T; #[inline] diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index bab4919eb6032..0bcf82e3ceff5 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -19,9 +19,10 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = {alloc::SHORT_TERM_VEC_PREFERS_COOP} -> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP }, +> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ // We can't just use a &mut VecDeque, as that would make Drain invariant over T // and we want it to be covariant instead deque: NonNull>, @@ -37,7 +38,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drain<'a, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ pub(super) unsafe fn new( deque: &'a mut VecDeque, drain_start: usize, @@ -91,8 +94,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl fmt::Debug + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain") .field(&self.drain_len) @@ -104,21 +110,37 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl Sync + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl Send + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "drain", since = "1.6.0")] impl Drop for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn drop(&mut self) { - struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> (&'r mut Drain<'a, T, A, COOP_PREFERRED>) - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; + struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool>( + &'r mut Drain<'a, T, A, COOP_PREFERRED>, + ) + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; - impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREFERRED> - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop + for DropGuard<'r, 'a, T, A, COOP_PREFERRED> + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { fn drop(&mut self) { if self.0.remaining != 0 { unsafe { @@ -200,7 +222,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = T; #[inline] @@ -222,8 +246,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl DoubleEndedIterator + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn next_back(&mut self) -> Option { if self.remaining == 0 { @@ -236,9 +263,15 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +impl ExactSizeIterator + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +{ +} diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index 477ab0c4db594..7924098c14db2 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -1,5 +1,5 @@ -use core::{alloc, fmt}; use core::iter::{FusedIterator, TrustedLen}; +use core::{alloc, fmt}; use crate::alloc::{Allocator, Global}; @@ -17,14 +17,17 @@ use super::VecDeque; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = true -> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + const COOP_PREFERRED: bool = true, +> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ inner: VecDeque, } impl IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ pub(super) fn new(inner: VecDeque) -> Self { IntoIter { inner } } @@ -36,7 +39,9 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { #[stable(feature = "collection_debug", since = "1.17.0")] impl fmt::Debug for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.inner).finish() } @@ -44,7 +49,9 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ type Item = T; #[inline] @@ -61,7 +68,9 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { #[stable(feature = "rust1", since = "1.0.0")] impl DoubleEndedIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ #[inline] fn next_back(&mut self) -> Option { self.inner.pop_back() @@ -70,16 +79,22 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ fn is_empty(&self) -> bool { self.inner.is_empty() } } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +impl FusedIterator for IntoIter where + [(); alloc::co_alloc_metadata_num_slots::()]: +{ +} #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +unsafe impl TrustedLen for IntoIter where + [(); alloc::co_alloc_metadata_num_slots::()]: +{ +} diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index fc260c4b79cf2..495cbf05f27ba 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -6,10 +6,9 @@ //! contained type is sendable. #![feature(global_co_alloc)] - #![stable(feature = "rust1", since = "1.0.0")] -use core::alloc::{self, GlobalAlloc}; use crate::vec::DEFAULT_COOP_PREFERRED; +use core::alloc::{self, GlobalAlloc}; use core::cmp::{self, Ordering}; use core::fmt; use core::hash::{Hash, Hasher}; @@ -97,9 +96,9 @@ mod tests; pub struct VecDeque< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED -> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED, +> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // `self[0]`, if it exists, is `buf[head]`. // `head < buf.capacity()`, unless `buf.capacity() == 0` when `head == 0`. @@ -112,8 +111,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl Clone + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn clone(&self) -> Self { let mut deq = Self::with_capacity_in(self.len(), self.allocator().clone()); deq.extend(self.iter().cloned()); @@ -127,8 +129,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn drop(&mut self) { /// Runs the destructor for all items in the slice when it gets dropped (normally or /// during unwinding). @@ -162,7 +167,9 @@ impl Default for VecDeque VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Marginally more convenient #[inline] fn ptr(&self) -> *mut T { @@ -452,13 +459,17 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE len: usize, ) -> usize { struct Guard<'a, T, A: Allocator, const COOP_PREFERRED: bool> - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { deque: &'a mut VecDeque, written: usize, } impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for Guard<'a, T, A, COOP_PREFERRED> - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { fn drop(&mut self) { self.deque.len += self.written; } @@ -536,8 +547,10 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } } -impl VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Creates an empty deque. /// /// # Examples @@ -573,7 +586,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } impl VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Creates an empty deque. /// /// # Examples @@ -2607,7 +2622,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } impl VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Modifies the deque in-place so that `len()` is equal to new_len, /// either by removing excess elements from the back or by appending clones of `value` /// to the back. @@ -2652,8 +2669,11 @@ fn wrap_index(logical_index: usize, capacity: usize) -> usize { } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialEq for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl PartialEq + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn eq(&self, other: &Self) -> bool { if self.len != other.len() { return false; @@ -2692,8 +2712,10 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl Eq for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +impl Eq for VecDeque where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +{ +} __impl_slice_eq1! { [] VecDeque, Vec, } __impl_slice_eq1! { [] VecDeque, &[U], } @@ -2703,8 +2725,11 @@ __impl_slice_eq1! { [const N: usize] VecDeque, &[U; N], } __impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N], } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl PartialOrd + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn partial_cmp(&self, other: &Self) -> Option { self.iter().partial_cmp(other.iter()) } @@ -2712,7 +2737,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl Ord for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn cmp(&self, other: &Self) -> Ordering { self.iter().cmp(other.iter()) @@ -2721,7 +2748,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl Hash for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn hash(&self, state: &mut H) { state.write_length_prefix(self.len); // It's not possible to use Hash::hash_slice on slices @@ -2736,7 +2765,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl Index for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Output = T; #[inline] @@ -2747,7 +2778,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl IndexMut for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn index_mut(&mut self, index: usize) -> &mut T { self.get_mut(index).expect("Out of bounds access") @@ -2756,7 +2789,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl FromIterator for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn from_iter>(iter: I) -> VecDeque { SpecFromIter::spec_from_iter(iter.into_iter()) } @@ -2764,7 +2799,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = T; type IntoIter = IntoIter; @@ -2776,8 +2813,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator + for &'a VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -2787,8 +2827,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a mut VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator + for &'a mut VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = &'a mut T; type IntoIter = IterMut<'a, T>; @@ -2799,7 +2842,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl Extend for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()); } @@ -2816,8 +2861,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: 'a + Copy, A: Allocator, const COOP_PREFERRED: bool> Extend<&'a T> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl<'a, T: 'a + Copy, A: Allocator, const COOP_PREFERRED: bool> Extend<&'a T> + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()); } @@ -2834,16 +2882,22 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl fmt::Debug + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.iter()).finish() } } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl From> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl From> + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Turn a [`Vec`] into a [`VecDeque`]. /// /// [`Vec`]: crate::vec::Vec @@ -2854,15 +2908,20 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// shouldn't be relied on. #[inline] fn from(other: Vec) -> Self - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(OTHER_COOP_PREFERRED)]: { + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(OTHER_COOP_PREFERRED)]:, + { let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc(); Self { head: 0, len, buf: unsafe { RawVec::from_raw_parts_in(ptr, cap, alloc) } } } } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl From> for Vec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl From> + for Vec +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Turn a [`VecDeque`] into a [`Vec`]. /// /// [`Vec`]: crate::vec::Vec @@ -2892,7 +2951,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// assert_eq!(vec, [8, 9, 1, 2, 3, 4]); /// assert_eq!(vec.as_ptr(), ptr); /// ``` - fn from(mut other: VecDeque) -> Self { + fn from( + mut other: VecDeque, + ) -> Self { other.make_contiguous(); unsafe { @@ -2912,8 +2973,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "std_collections_from_array", since = "1.56.0")] -impl From<[T; N]> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl From<[T; N]> + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Converts a `[T; N]` into a `VecDeque`. /// /// ``` diff --git a/library/alloc/src/collections/vec_deque/spec_extend.rs b/library/alloc/src/collections/vec_deque/spec_extend.rs index cdeda1a57bed5..b1a9d23fd4a99 100644 --- a/library/alloc/src/collections/vec_deque/spec_extend.rs +++ b/library/alloc/src/collections/vec_deque/spec_extend.rs @@ -13,10 +13,11 @@ pub(super) trait SpecExtend { fn spec_extend(&mut self, iter: I); } -impl SpecExtend for VecDeque +impl SpecExtend + for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, mut iter: I) { // This function should be the moral equivalent of: @@ -26,8 +27,12 @@ where // } // May only be called if `deque.len() < deque.capacity()` - unsafe fn push_unchecked(deque: &mut VecDeque, element: T) - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + unsafe fn push_unchecked( + deque: &mut VecDeque, + element: T, + ) where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { // SAFETY: Because of the precondition, it's guaranteed that there is space // in the logical array after the last element. unsafe { deque.buffer_write(deque.to_physical_idx(deque.len), element) }; @@ -54,10 +59,11 @@ where } } -impl SpecExtend for VecDeque +impl SpecExtend + for VecDeque where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iter: I) { // This is the case for a TrustedLen iterator. @@ -90,8 +96,11 @@ where } } -impl SpecExtend> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl SpecExtend> + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn spec_extend(&mut self, mut iterator: vec::IntoIter) { let slice = iterator.as_slice(); self.reserve(slice.len()); @@ -104,21 +113,23 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } } -impl<'a, T: 'a, I, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, I> for VecDeque +impl<'a, T: 'a, I, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, I> + for VecDeque where I: Iterator, T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.copied()) } } -impl<'a, T: 'a, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, slice::Iter<'a, T>> for VecDeque +impl<'a, T: 'a, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, slice::Iter<'a, T>> + for VecDeque where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index b9641ef156c88..85dd756337350 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -7,10 +7,11 @@ pub(super) trait SpecFromIter { fn spec_from_iter(iter: I) -> Self; } -impl SpecFromIter for VecDeque +impl SpecFromIter + for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_from_iter(iterator: I) -> Self { // Since converting is O(1) now, just re-use the `Vec` logic for @@ -21,16 +22,22 @@ where } } -impl SpecFromIter> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl SpecFromIter> + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { iterator.into_vecdeque() } } -impl SpecFromIter> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl SpecFromIter> + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn spec_from_iter(iterator: IntoIter) -> Self { iterator.into_vecdeque() diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 58e8d72fc2d25..84fd954edbd7a 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -1,6 +1,6 @@ #![unstable(feature = "raw_vec_internals", reason = "unstable const warnings", issue = "none")] -use core::alloc::{self, LayoutError, GlobalCoAllocMeta, PtrAndMeta}; +use core::alloc::{self, GlobalCoAllocMeta, LayoutError, PtrAndMeta}; use core::cmp; use core::intrinsics; use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; @@ -50,8 +50,12 @@ enum AllocInit { /// `usize::MAX`. This means that you need to be careful when round-tripping this type with a /// `Box<[T]>`, since `capacity()` won't yield the length. #[allow(missing_debug_implementations)] -pub(crate) struct RawVec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +pub(crate) struct RawVec< + T, + A: Allocator = Global, + const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED, +> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { ptr: Unique, cap: usize, @@ -59,11 +63,14 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE // As of v1.67.0, `cmp` for `TypeId` is not `const`, unfortunately: //pub(crate) meta: [GlobalCoAllocMeta; {if core::any::TypeId::of::()==core::any::TypeId::of::() {1} else {0}}], //pub(crate) meta: [GlobalCoAllocMeta; mem::size_of::()], - pub(crate) metas: [GlobalCoAllocMeta; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + pub(crate) metas: [GlobalCoAllocMeta; + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], } impl RawVec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// HACK(Centril): This exists because stable `const fn` can only call stable `const fn`, so /// they cannot call `Self::new()`. /// @@ -111,7 +118,8 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PRE } impl RawVec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // Tiny Vecs are dumb. Skip to: // - 8 if the element size is 1, because any heap allocators is likely @@ -130,8 +138,13 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// the returned `RawVec`. pub const fn new_in(alloc: A) -> Self { // `cap: 0` means "unallocated". zero-sized types are ignored. - Self { ptr: Unique::dangling(), cap: 0, alloc, - metas: [GlobalCoAllocMeta {/*one: 1*/ /* , two: 2, three: 3, four: 4*/}; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)] } + Self { + ptr: Unique::dangling(), + cap: 0, + alloc, + metas: [GlobalCoAllocMeta {/*one: 1*/ /* , two: 2, three: 3, four: 4*/}; + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + } } /// Like `with_capacity`, but parameterized over the choice of @@ -208,7 +221,8 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE ptr: unsafe { Unique::new_unchecked(ptr.cast().as_ptr()) }, cap: capacity, alloc, - metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)] + metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], } } } @@ -225,7 +239,13 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// guaranteed. #[inline] pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, alloc: A) -> Self { - Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc, metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)] } + Self { + ptr: unsafe { Unique::new_unchecked(ptr) }, + cap: capacity, + alloc, + metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + } } /// Gets a raw pointer to the start of the allocation. Note that this is @@ -293,8 +313,8 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE slf: &mut RawVec, len: usize, additional: usize, - ) - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + ) where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { handle_reserve(slf.grow_amortized(len, additional)); } @@ -369,17 +389,16 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } impl RawVec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Returns if the buffer needs to grow to fulfill the needed extra capacity. /// Mainly used to make inlining reserve-calls possible without inlining `grow`. - fn needs_to_grow(&self, len: usize, additional: usize) -> bool - { + fn needs_to_grow(&self, len: usize, additional: usize) -> bool { additional > self.capacity().wrapping_sub(len) } - fn set_ptr_and_cap(&mut self, ptr: NonNull<[u8]>, cap: usize) - { + fn set_ptr_and_cap(&mut self, ptr: NonNull<[u8]>, cap: usize) { // Allocators currently return a `NonNull<[u8]>` whose length matches // the size requested. If that ever changes, the capacity here should // change to `ptr.len() / mem::size_of::()`. @@ -490,15 +509,17 @@ where memory.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () }.into()) } -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for RawVec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop + for RawVec +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. default fn drop(&mut self) { if let Some((ptr, layout)) = self.current_memory() { if A::IS_CO_ALLOCATOR && COOP_PREFERRED { let meta = self.metas[0]; - unsafe { self.alloc.co_deallocate(PtrAndMeta {ptr, meta}, layout) } + unsafe { self.alloc.co_deallocate(PtrAndMeta { ptr, meta }, layout) } } else { unsafe { self.alloc.deallocate(ptr, layout) } } @@ -508,7 +529,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE // @FIXME Custom unsafe impl<#[may_dangle] T, const COOP_PREFERRED: bool> Drop for RawVec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. fn drop(&mut self) { // @TOFIXMEDO diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 447721d342613..1d55e4f87c555 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -92,8 +92,12 @@ pub(crate) mod hack { // We shouldn't add inline attribute to this since this is used in // `vec!` macro mostly and causes perf regression. See #71204 for // discussion and perf results. - pub fn into_vec(b: Box<[T], A>) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + pub fn into_vec( + b: Box<[T], A>, + ) -> Vec + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { unsafe { let len = b.len(); let (b, alloc) = Box::into_raw_with_allocator(b); @@ -103,14 +107,22 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] #[inline] - pub fn to_vec(s: &[T], alloc: A) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + pub fn to_vec( + s: &[T], + alloc: A, + ) -> Vec + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { T::to_vec(s, alloc) } #[cfg(not(no_global_oom_handling))] pub trait ConvertVec { - fn to_vec(s: &[Self], alloc: A) -> Vec + fn to_vec( + s: &[Self], + alloc: A, + ) -> Vec where Self: Sized, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; @@ -119,15 +131,24 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] impl ConvertVec for T { #[inline] - default fn to_vec(s: &[Self], alloc: A) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + default fn to_vec( + s: &[Self], + alloc: A, + ) -> Vec + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool> - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { vec: &'a mut Vec, num_init: usize, } impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'a, T, A, COOP_PREFERRED> - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { #[inline] fn drop(&mut self) { // SAFETY: @@ -159,8 +180,13 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] impl ConvertVec for T { #[inline] - fn to_vec(s: &[Self], alloc: A) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + fn to_vec( + s: &[Self], + alloc: A, + ) -> Vec + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { let mut v = Vec::with_capacity_in(s.len(), alloc); // SAFETY: // allocated above with the capacity of `s`, and initialize to `s.len()` in @@ -438,7 +464,7 @@ impl [T] { pub fn to_vec_in(&self, alloc: A) -> Vec where T: Clone, - [(); core::alloc::co_alloc_metadata_num_slots::()]: + [(); core::alloc::co_alloc_metadata_num_slots::()]:, { // N.B., see the `hack` module in this file for more details. hack::to_vec(self, alloc) @@ -462,7 +488,9 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn into_vec(self: Box) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots::()]: { + where + [(); core::alloc::co_alloc_metadata_num_slots::()]:, + { // N.B., see the `hack` module in this file for more details. hack::into_vec(self) } @@ -774,7 +802,9 @@ impl> Join<&[T]> for [V] { #[stable(feature = "rust1", since = "1.0.0")] impl Borrow<[T]> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn borrow(&self) -> &[T] { &self[..] } @@ -782,7 +812,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[stable(feature = "rust1", since = "1.0.0")] impl BorrowMut<[T]> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn borrow_mut(&mut self) -> &mut [T] { &mut self[..] } diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index bbcf76297ebb4..15260482532ba 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -23,9 +23,10 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, - const COOP_PREFERRED: bool = {alloc::SHORT_TERM_VEC_PREFERS_COOP} -> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP }, +> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Index of tail to preserve pub(super) tail_start: usize, /// Length of tail @@ -36,15 +37,20 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl fmt::Debug + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() } } impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drain<'a, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Returns the remaining items of this iterator as a slice. /// /// # Examples @@ -144,22 +150,34 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "vec_drain_as_slice", since = "1.46.0")] impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> AsRef<[T]> for Drain<'a, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn as_ref(&self) -> &[T] { self.as_slice() } } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl Sync + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl Send + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = T; #[inline] @@ -173,8 +191,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl DoubleEndedIterator + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn next_back(&mut self) -> Option { self.iter.next_back().map(|elt| unsafe { ptr::read(elt as *const _) }) @@ -183,14 +204,22 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "drain", since = "1.6.0")] impl Drop for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn drop(&mut self) { /// Moves back the un-`Drain`ed elements to restore the original `Vec`. - struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool>(&'r mut Drain<'a, T, A, COOP_PREFERRED>) - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: ; - - impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREFERRED> - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool>( + &'r mut Drain<'a, T, A, COOP_PREFERRED>, + ) + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; + + impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop + for DropGuard<'r, 'a, T, A, COOP_PREFERRED> + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { fn drop(&mut self) { if self.0.tail_len > 0 { unsafe { @@ -254,17 +283,26 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl ExactSizeIterator + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn is_empty(&self) -> bool { self.iter.is_empty() } } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl TrustedLen + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +{ +} diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/drain_filter.rs index 7be4abacbec96..89baafca46729 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/library/alloc/src/vec/drain_filter.rs @@ -24,10 +24,10 @@ pub struct DrainFilter< T, F, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = true + const COOP_PREFERRED: bool = true, > where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { pub(super) vec: &'a mut Vec, /// The index of the item that will be inspected by the next call to `next`. @@ -49,7 +49,7 @@ pub struct DrainFilter< impl DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] @@ -115,10 +115,11 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl Iterator for DrainFilter<'_, T, F, A, COOP_PREFERRED> +impl Iterator + for DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = T; @@ -154,24 +155,26 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl Drop for DrainFilter<'_, T, F, A, COOP_PREFERRED> +impl Drop + for DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator, const COOP_PREFERRED: bool> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { drain: &'b mut DrainFilter<'a, T, F, A, COOP_PREFERRED>, } - impl<'a, 'b, T, F, A: Allocator, const COOP_PREFERRED: bool> Drop for BackshiftOnDrop<'a, 'b, T, F, A, COOP_PREFERRED> + impl<'a, 'b, T, F, A: Allocator, const COOP_PREFERRED: bool> Drop + for BackshiftOnDrop<'a, 'b, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { unsafe { diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 3f1c3c8418220..211652650bc53 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -4,7 +4,6 @@ use crate::alloc::{Allocator, Global}; #[cfg(not(no_global_oom_handling))] use crate::collections::VecDeque; use crate::raw_vec::RawVec; -use core::{alloc, array, fmt}; use core::iter::{ FusedIterator, InPlaceIterable, SourceIter, TrustedLen, TrustedRandomAccessNoCoerce, }; @@ -14,6 +13,7 @@ use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; use core::ops::Deref; use core::ptr::{self, NonNull}; use core::slice::{self}; +use core::{alloc, array, fmt}; /// An iterator that moves out of a vector. /// @@ -31,9 +31,10 @@ use core::slice::{self}; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = {alloc::SHORT_TERM_VEC_PREFERS_COOP} -> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP }, +> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ pub(super) buf: NonNull, pub(super) phantom: PhantomData, pub(super) cap: usize, @@ -45,15 +46,20 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "vec_intoiter_debug", since = "1.13.0")] -impl fmt::Debug for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl fmt::Debug + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.as_slice()).finish() } } impl IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Returns the remaining items of this iterator as a slice. /// /// # Examples @@ -168,22 +174,34 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")] impl AsRef<[T]> for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn as_ref(&self) -> &[T] { self.as_slice() } } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Send for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl Send + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Sync for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl Sync + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = T; #[inline] @@ -300,8 +318,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl DoubleEndedIterator + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn next_back(&mut self) -> Option { if self.end == self.ptr { @@ -342,20 +363,29 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl ExactSizeIterator + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn is_empty(&self) -> bool { self.ptr == self.end } } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +impl FusedIterator for IntoIter where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +{ +} #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl TrustedLen + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[doc(hidden)] #[unstable(issue = "none", feature = "std_internals")] @@ -371,18 +401,22 @@ impl NonDrop for T {} #[unstable(issue = "none", feature = "std_internals")] // TrustedRandomAccess (without NoCoerce) must not be implemented because // subtypes/supertypes of `T` might not be `NonDrop` -unsafe impl TrustedRandomAccessNoCoerce for IntoIter +unsafe impl TrustedRandomAccessNoCoerce + for IntoIter where T: NonDrop, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { const MAY_HAVE_SIDE_EFFECT: bool = false; } #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_into_iter_clone", since = "1.8.0")] -impl Clone for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl Clone + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[cfg(not(test))] fn clone(&self) -> Self { self.as_slice().to_vec_in(self.alloc.deref().clone()).into_iter() @@ -394,20 +428,32 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn drop(&mut self) { - struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool>(&'a mut IntoIter) - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: ; + struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool>( + &'a mut IntoIter, + ) + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; impl Drop for DropGuard<'_, T, A, COOP_PREFERRED> - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { fn drop(&mut self) { unsafe { // `IntoIter::alloc` is not used anymore after this and will be dropped by RawVec let alloc = ManuallyDrop::take(&mut self.0.alloc); // RawVec handles deallocation - let _ = RawVec::::from_raw_parts_in(self.0.buf.as_ptr(), self.0.cap, alloc); + let _ = RawVec::::from_raw_parts_in( + self.0.buf.as_ptr(), + self.0.cap, + alloc, + ); } } } @@ -425,13 +471,20 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE // also refer to the vec::in_place_collect module documentation to get an overview #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl InPlaceIterable for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl InPlaceIterable + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl SourceIter for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +unsafe impl SourceIter + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Source = Self; #[inline] diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 1f28c5d5a0d5c..ee29e600dda1e 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -397,19 +397,25 @@ mod spec_extend; #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "Vec")] #[rustc_insignificant_dtor] -pub struct Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +pub struct Vec< + T, + #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED, +> where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { buf: RawVec, len: usize, } #[unstable(feature = "global_co_alloc_covec", issue = "none")] -pub type CoVec = Vec; +pub type CoVec = + Vec; /// "Plain" Vec. Not "cooperative" - not carrying extra data to assist the allocator. #[unstable(feature = "global_co_alloc_plvec", issue = "none")] -pub type PlVec = Vec; +pub type PlVec = + Vec; /// Default `Vec`, `DefVec`, `DecVeque`, `DefDecVeq` "cooperation" (`COOP_PREFERRED`) generic parameter. #[unstable(feature = "global_co_alloc_def", issue = "none")] @@ -419,14 +425,14 @@ pub const DEFAULT_COOP_PREFERRED: bool = true; /// difference to `Vec` (used without specifying `COOP_PREFERRED`): `DefVec` indicates that the /// author considered using `CoVec` or `PlVec`, but left it to default instead. #[unstable(feature = "global_co_alloc_defvec", issue = "none")] -pub type DefVec = Vec; - +pub type DefVec = + Vec; /// "Weighted cooperative" Vec. Weight means how much it wants to cooperate (with the allocator). 0 /// = always pack; u8::MAX = always cooperate (if `Global` supports it). /// @FIXME A `pub const` threshold. #[unstable(feature = "global_co_alloc_vec", issue = "none")] -pub type WeVec = Vec1}>; +pub type WeVec = Vec 1 }>; //////////////////////////////////////////////////////////////////////////////// // Inherent methods @@ -617,7 +623,9 @@ impl Vec { } impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Constructs a new, empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. @@ -1628,8 +1636,10 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR // This drop guard will be invoked when predicate or `drop` of element panicked. // It shifts unchecked elements to cover holes and `set_len` to the correct length. // In cases when predicate and `drop` never panick, it will be optimized out. - struct BackshiftOnDrop<'a, T, A: Allocator, const VEC_IS_COOP: bool=true> - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]: { + struct BackshiftOnDrop<'a, T, A: Allocator, const VEC_IS_COOP: bool = true> + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, + { v: &'a mut Vec, processed_len: usize, deleted_cnt: usize, @@ -1637,7 +1647,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } impl Drop for BackshiftOnDrop<'_, T, A, VEC_IS_COOP> - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]: { + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, + { fn drop(&mut self) { if self.deleted_cnt > 0 { // SAFETY: Trailing unchecked items must be valid since we never touch them. @@ -1656,7 +1668,12 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } } - let mut g = BackshiftOnDrop:: { v: self, processed_len: 0, deleted_cnt: 0, original_len }; + let mut g = BackshiftOnDrop:: { + v: self, + processed_len: 0, + deleted_cnt: 0, + original_len, + }; fn process_loop( original_len: usize, @@ -1664,7 +1681,7 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR g: &mut BackshiftOnDrop<'_, T, A, VEC_IS_COOP>, ) where F: FnMut(&mut T) -> bool, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]: + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, { while g.processed_len != original_len { // SAFETY: Unchecked element must be valid. @@ -1758,7 +1775,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR /* INVARIANT: vec.len() > read >= write > write-1 >= 0 */ struct FillGapOnDrop<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { /* Offset of the element we want to check if it is duplicate */ read: usize, @@ -1770,8 +1789,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR vec: &'a mut Vec, } - impl<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> Drop for FillGapOnDrop<'a, T, A, COOP_PREFERRED> - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + impl<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> Drop + for FillGapOnDrop<'a, T, A, COOP_PREFERRED> + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { fn drop(&mut self) { /* This code gets executed when `same_bucket` panics */ @@ -2365,7 +2387,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Resizes the `Vec` in-place so that `len` is equal to `new_len`. /// /// If `new_len` is greater than `len`, the `Vec` is extended by the @@ -2465,7 +2489,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } impl Vec<[T; N], A, COOP_PREFERRED> -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Takes a `Vec<[T; N]>` and flattens it into a `Vec`. /// /// # Panics @@ -2527,7 +2553,9 @@ impl ExtendWith for ExtendElement { } impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[cfg(not(no_global_oom_handling))] /// Extend the vector by `n` values, using the given generator. fn extend_with>(&mut self, n: usize, mut value: E) { @@ -2560,7 +2588,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Removes consecutive repeated elements in the vector according to the /// [`PartialEq`] trait implementation. /// @@ -2596,8 +2626,14 @@ pub fn from_elem(elem: T, n: usize) -> Vec { #[doc(hidden)] #[cfg(not(no_global_oom_handling))] #[unstable(feature = "allocator_api", issue = "32838")] -pub fn from_elem_in(elem: T, n: usize, alloc: A) -> Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +pub fn from_elem_in( + elem: T, + n: usize, + alloc: A, +) -> Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ ::from_elem(elem, n, alloc) } @@ -2609,8 +2645,11 @@ trait ExtendFromWithinSpec { unsafe fn spec_extend_from_within(&mut self, src: Range); } -impl ExtendFromWithinSpec for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl ExtendFromWithinSpec + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ default unsafe fn spec_extend_from_within(&mut self, src: Range) { // SAFETY: // - len is increased only after initializing elements @@ -2629,8 +2668,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } } -impl ExtendFromWithinSpec for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl ExtendFromWithinSpec + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ unsafe fn spec_extend_from_within(&mut self, src: Range) { let count = src.len(); { @@ -2664,7 +2706,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[stable(feature = "rust1", since = "1.0.0")] impl ops::Deref for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Target = [T]; #[inline] @@ -2675,7 +2719,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[stable(feature = "rust1", since = "1.0.0")] impl ops::DerefMut for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn deref_mut(&mut self) -> &mut [T] { unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) } @@ -2689,7 +2735,9 @@ trait SpecCloneFrom { #[cfg(not(no_global_oom_handling))] impl SpecCloneFrom for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ default fn clone_from(this: &mut Self, other: &Self) { // drop anything that will not be overwritten this.truncate(other.len()); @@ -2706,7 +2754,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[cfg(not(no_global_oom_handling))] impl SpecCloneFrom for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn clone_from(this: &mut Self, other: &Self) { this.clear(); this.extend_from_slice(other); @@ -2716,7 +2766,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[cfg(not(test))] fn clone(&self) -> Self { let alloc = self.allocator().clone(); @@ -2752,7 +2804,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR /// ``` #[stable(feature = "rust1", since = "1.0.0")] impl Hash for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn hash(&self, state: &mut H) { Hash::hash(&**self, state) @@ -2764,8 +2818,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl, A: Allocator, const COOP_PREFERRED: bool> Index for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl, A: Allocator, const COOP_PREFERRED: bool> Index + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Output = I::Output; #[inline] @@ -2779,8 +2836,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl, A: Allocator, const COOP_PREFERRED: bool> IndexMut for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl, A: Allocator, const COOP_PREFERRED: bool> IndexMut + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn index_mut(&mut self, index: I) -> &mut Self::Output { IndexMut::index_mut(&mut **self, index) @@ -2798,7 +2858,9 @@ impl FromIterator for Vec { #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = T; type IntoIter = IntoIter; @@ -2844,7 +2906,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = &'a T; type IntoIter = slice::Iter<'a, T>; @@ -2854,8 +2918,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a mut Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator + for &'a mut Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = &'a mut T; type IntoIter = slice::IterMut<'a, T>; @@ -2867,7 +2934,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] impl Extend for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()) @@ -2885,7 +2954,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ // leaf method to which various SpecFrom/SpecExtend implementations delegate when // they have no further optimizations to apply #[cfg(not(no_global_oom_handling))] @@ -3059,8 +3130,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR /// [`copy_from_slice`]: slice::copy_from_slice #[cfg(not(no_global_oom_handling))] #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: Copy + 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> Extend<&'a T> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl<'a, T: Copy + 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> Extend<&'a T> + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()) } @@ -3078,8 +3152,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR /// Implements comparison of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl PartialOrd + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn partial_cmp(&self, other: &Self) -> Option { PartialOrd::partial_cmp(&**self, &**other) @@ -3087,13 +3164,17 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } #[stable(feature = "rust1", since = "1.0.0")] -impl Eq for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +impl Eq for Vec where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +{ +} /// Implements ordering of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] impl Ord for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn cmp(&self, other: &Self) -> Ordering { Ord::cmp(&**self, &**other) @@ -3101,8 +3182,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn drop(&mut self) { unsafe { // use drop for [T] @@ -3126,24 +3210,33 @@ impl const Default for Vec { } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl fmt::Debug + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) } } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl AsRef> + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn as_ref(&self) -> &Vec { self } } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl AsMut> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl AsMut> + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn as_mut(&mut self) -> &mut Vec { self } @@ -3151,7 +3244,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<[T]> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn as_ref(&self) -> &[T] { self } @@ -3159,7 +3254,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[stable(feature = "vec_as_mut", since = "1.5.0")] impl AsMut<[T]> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn as_mut(&mut self) -> &mut [T] { self } @@ -3257,7 +3354,9 @@ where #[cfg(not(test))] #[stable(feature = "vec_from_box", since = "1.18.0")] impl From> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Convert a boxed slice into a vector by transferring ownership of /// the existing heap allocation. /// @@ -3277,7 +3376,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[cfg(not(test))] #[stable(feature = "box_from_vec", since = "1.20.0")] impl From> for Box<[T], A> -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Convert a vector into a boxed slice. /// /// If `v` has excess capacity, its items will be moved into a @@ -3317,8 +3418,11 @@ impl From<&str> for Vec { } #[stable(feature = "array_try_from_vec", since = "1.48.0")] -impl TryFrom> for [T; N] -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl TryFrom> + for [T; N] +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Error = Vec; /// Gets the entire contents of the `Vec` as an array, diff --git a/library/alloc/src/vec/spec_extend.rs b/library/alloc/src/vec/spec_extend.rs index 87bdb3aaab7a5..73cf325889290 100644 --- a/library/alloc/src/vec/spec_extend.rs +++ b/library/alloc/src/vec/spec_extend.rs @@ -1,5 +1,5 @@ -use core::alloc; use crate::alloc::Allocator; +use core::alloc; use core::iter::TrustedLen; use core::slice::{self}; @@ -13,7 +13,7 @@ pub(super) trait SpecExtend { impl SpecExtend for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iter: I) { self.extend_desugared(iter) @@ -23,15 +23,18 @@ where impl SpecExtend for Vec where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iterator: I) { self.extend_trusted(iterator) } } -impl SpecExtend> for Vec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl SpecExtend> + for Vec +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn spec_extend(&mut self, mut iterator: IntoIter) { unsafe { self.append_elements(iterator.as_slice() as _); @@ -40,21 +43,23 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } } -impl<'a, T: 'a, I, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, I> for Vec +impl<'a, T: 'a, I, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, I> + for Vec where I: Iterator, T: Clone, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.cloned()) } } -impl<'a, T: 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec +impl<'a, T: 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, slice::Iter<'a, T>> + for Vec where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/vec/spec_from_elem.rs b/library/alloc/src/vec/spec_from_elem.rs index 682375a607837..3766f6de061bb 100644 --- a/library/alloc/src/vec/spec_from_elem.rs +++ b/library/alloc/src/vec/spec_from_elem.rs @@ -1,20 +1,31 @@ use core::ptr; -use core::alloc; use crate::alloc::Allocator; use crate::raw_vec::RawVec; +use core::alloc; use super::{ExtendElement, IsZero, Vec}; // Specialization trait used for Vec::from_elem pub(super) trait SpecFromElem: Sized { - fn from_elem(elem: Self, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots::(COOP_PREFERRED)]: ; + fn from_elem( + elem: Self, + n: usize, + alloc: A, + ) -> Vec + where + [(); alloc::co_alloc_metadata_num_slots::(COOP_PREFERRED)]:; } impl SpecFromElem for T { - default fn from_elem(elem: Self, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + default fn from_elem( + elem: Self, + n: usize, + alloc: A, + ) -> Vec + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { let mut v = Vec::with_capacity_in(n, alloc); v.extend_with(n, ExtendElement(elem)); v @@ -23,8 +34,14 @@ impl SpecFromElem for T { impl SpecFromElem for T { #[inline] - default fn from_elem(elem: T, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + default fn from_elem( + elem: T, + n: usize, + alloc: A, + ) -> Vec + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { if elem.is_zero() { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } @@ -36,8 +53,14 @@ impl SpecFromElem for T { impl SpecFromElem for i8 { #[inline] - fn from_elem(elem: i8, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + fn from_elem( + elem: i8, + n: usize, + alloc: A, + ) -> Vec + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } @@ -52,8 +75,14 @@ impl SpecFromElem for i8 { impl SpecFromElem for u8 { #[inline] - fn from_elem(elem: u8, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + fn from_elem( + elem: u8, + n: usize, + alloc: A, + ) -> Vec + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index edf02df909eb9..0397995747ee5 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -1,5 +1,5 @@ -use core::alloc; use crate::alloc::{Allocator, Global}; +use core::alloc; use core::ptr::{self}; use core::slice::{self}; @@ -23,15 +23,18 @@ pub struct Splice< 'a, I: Iterator + 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, -> -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +> where + [(); core::alloc::co_alloc_metadata_num_slots::()]:, +{ pub(super) drain: Drain<'a, I::Item, A>, pub(super) replace_with: I, } #[stable(feature = "vec_splice", since = "1.21.0")] impl Iterator for Splice<'_, I, A> -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +where + [(); core::alloc::co_alloc_metadata_num_slots::()]:, +{ type Item = I::Item; fn next(&mut self) -> Option { @@ -45,19 +48,25 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[stable(feature = "vec_splice", since = "1.21.0")] impl DoubleEndedIterator for Splice<'_, I, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ fn next_back(&mut self) -> Option { self.drain.next_back() } } #[stable(feature = "vec_splice", since = "1.21.0")] -impl ExactSizeIterator for Splice<'_, I, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +impl ExactSizeIterator for Splice<'_, I, A> where + [(); alloc::co_alloc_metadata_num_slots::()]: +{ +} #[stable(feature = "vec_splice", since = "1.21.0")] impl Drop for Splice<'_, I, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ fn drop(&mut self) { self.drain.by_ref().for_each(drop); @@ -99,7 +108,9 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { /// Private helper methods for `Splice::drop` impl Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ /// The range from `self.vec.len` to `self.tail_start` contains elements /// that have been moved out. /// Fill that range as much as possible with new elements from the `replace_with` iterator. diff --git a/library/alloc/tests/boxed.rs b/library/alloc/tests/boxed.rs index c34e7a558061d..656e079f9c61c 100644 --- a/library/alloc/tests/boxed.rs +++ b/library/alloc/tests/boxed.rs @@ -61,7 +61,7 @@ fn box_deref_lval() { pub struct ConstAllocator; -//@TODO +//@FIXME unsafe impl const Allocator for ConstAllocator { fn allocate(&self, layout: Layout) -> Result, AllocError> { match layout.size() { diff --git a/library/core/src/alloc/global.rs b/library/core/src/alloc/global.rs index b0d457ff8c4d9..a7251328c128b 100644 --- a/library/core/src/alloc/global.rs +++ b/library/core/src/alloc/global.rs @@ -1,7 +1,7 @@ +use crate::alloc::GlobalCoAllocMeta; use crate::alloc::Layout; use crate::cmp; use crate::ptr; -use crate::alloc::GlobalCoAllocMeta; #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] @@ -166,7 +166,9 @@ pub unsafe trait GlobalAlloc { unsafe fn alloc(&self, layout: Layout) -> *mut u8; #[unstable(feature = "global_co_alloc", issue = "none")] - unsafe fn co_alloc(&self, _layout: Layout, mut _result: &mut RawAndMeta) {panic!("@FIXME")} + unsafe fn co_alloc(&self, _layout: Layout, mut _result: &mut RawAndMeta) { + panic!("@FIXME") + } /// Deallocate the block of memory at the given `ptr` pointer with the given `layout`. /// @@ -184,7 +186,9 @@ pub unsafe trait GlobalAlloc { unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout); #[unstable(feature = "global_co_alloc", issue = "none")] - unsafe fn co_dealloc(&self, _ptr_and_meta: RawAndMeta, _layout: Layout) {panic!("@FIXME")} + unsafe fn co_dealloc(&self, _ptr_and_meta: RawAndMeta, _layout: Layout) { + panic!("@FIXME") + } /// Behaves like `alloc`, but also ensures that the contents /// are set to zero before being returned. @@ -308,7 +312,7 @@ pub unsafe trait GlobalAlloc { ptr_and_meta: RawAndMeta, layout: Layout, new_size: usize, - mut result: &mut RawAndMeta + mut result: &mut RawAndMeta, ) { // SAFETY: the caller must ensure that the `new_size` does not overflow. // `layout.align()` comes from a `Layout` and is thus guaranteed to be valid. diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index f67bdf35b9416..f8200a774839e 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -90,7 +90,9 @@ pub const fn co_alloc_metadata_num_slots() -> usize { #[unstable(feature = "global_co_alloc", issue = "none")] /// Param `coop_preferred` - if false, then this returns `0`, regardless of /// whether allocator `A` is cooperative. -pub const fn co_alloc_metadata_num_slots_with_preference(coop_preferred: bool) -> usize { +pub const fn co_alloc_metadata_num_slots_with_preference( + coop_preferred: bool, +) -> usize { if A::IS_CO_ALLOCATOR && coop_preferred { 1 } else { 0 } } @@ -183,7 +185,9 @@ pub unsafe trait Allocator { /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html fn allocate(&self, layout: Layout) -> Result, AllocError>; - fn co_allocate(&self, _layout: Layout, _result: &mut SliceAndMetaResult) {panic!("FIXME")} + fn co_allocate(&self, _layout: Layout, _result: &mut SliceAndMetaResult) { + panic!("FIXME") + } /// Behaves like `allocate`, but also ensures that the returned memory is zero-initialized. /// @@ -209,14 +213,9 @@ pub unsafe trait Allocator { fn co_allocate_zeroed(&self, layout: Layout, mut result: &mut SliceAndMetaResult) { self.co_allocate(layout, &mut result); - if let Ok(SliceAndMeta{slice, ..}) = result { + if let Ok(SliceAndMeta { slice, .. }) = result { // SAFETY: `alloc` returns a valid memory block - unsafe { - slice - .as_non_null_ptr() - .as_ptr() - .write_bytes(0, slice.len()) - } + unsafe { slice.as_non_null_ptr().as_ptr().write_bytes(0, slice.len()) } } } @@ -231,7 +230,9 @@ pub unsafe trait Allocator { /// [*fit*]: #memory-fitting unsafe fn deallocate(&self, ptr: NonNull, layout: Layout); - unsafe fn co_deallocate(&self, _ptr_and_meta: PtrAndMeta, _layout: Layout) {panic!("FIXME")} + unsafe fn co_deallocate(&self, _ptr_and_meta: PtrAndMeta, _layout: Layout) { + panic!("FIXME") + } /// Attempts to extend the memory block. /// @@ -302,7 +303,7 @@ pub unsafe trait Allocator { ptr_and_meta: PtrAndMeta, old_layout: Layout, new_layout: Layout, - mut result: &mut SliceAndMetaResult + mut result: &mut SliceAndMetaResult, ) { debug_assert!( new_layout.size() >= old_layout.size(), @@ -311,7 +312,7 @@ pub unsafe trait Allocator { self.co_allocate(new_layout, &mut result); - if let Ok(SliceAndMeta {slice, ..}) = result { + if let Ok(SliceAndMeta { slice, .. }) = result { // SAFETY: because `new_layout.size()` must be greater than or equal to // `old_layout.size()`, both the old and new memory allocation are valid for reads and // writes for `old_layout.size()` bytes. Also, because the old allocation wasn't yet @@ -396,7 +397,7 @@ pub unsafe trait Allocator { ptr_and_meta: PtrAndMeta, old_layout: Layout, new_layout: Layout, - mut result: &mut SliceAndMetaResult + mut result: &mut SliceAndMetaResult, ) { debug_assert!( new_layout.size() >= old_layout.size(), @@ -405,7 +406,7 @@ pub unsafe trait Allocator { self.co_allocate_zeroed(new_layout, &mut result); - if let Ok(SliceAndMeta{ slice, ..}) = result { + if let Ok(SliceAndMeta { slice, .. }) = result { // SAFETY: because `new_layout.size()` must be greater than or equal to // `old_layout.size()`, both the old and new memory allocation are valid for reads and // writes for `old_layout.size()` bytes. Also, because the old allocation wasn't yet @@ -491,7 +492,7 @@ pub unsafe trait Allocator { ptr_and_meta: PtrAndMeta, old_layout: Layout, new_layout: Layout, - mut result: &mut SliceAndMetaResult + mut result: &mut SliceAndMetaResult, ) { debug_assert!( new_layout.size() <= old_layout.size(), @@ -500,7 +501,7 @@ pub unsafe trait Allocator { self.co_allocate(new_layout, &mut result); - if let Ok(SliceAndMeta{ slice, ..}) = result { + if let Ok(SliceAndMeta { slice, .. }) = result { // SAFETY: because `new_layout.size()` must be lower than or equal to // `old_layout.size()`, both the old and new memory allocation are valid for reads and // writes for `new_layout.size()` bytes. Also, because the old allocation wasn't yet diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs index 33d1ee065de2a..63045ebcb8157 100644 --- a/library/std/src/io/cursor.rs +++ b/library/std/src/io/cursor.rs @@ -403,7 +403,9 @@ fn reserve_and_pad( vec: &mut Vec, buf_len: usize, ) -> io::Result -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ let pos: usize = (*pos_mut).try_into().map_err(|_| { io::const_io_error!( ErrorKind::InvalidInput, @@ -442,10 +444,14 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// Writes the slice to the vec without allocating /// # Safety: vec must have buf.len() spare capacity -unsafe fn vec_write_unchecked(pos: usize, vec: &mut Vec, buf: &[u8]) -> usize +unsafe fn vec_write_unchecked( + pos: usize, + vec: &mut Vec, + buf: &[u8], +) -> usize where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { debug_assert!(vec.capacity() >= pos + buf.len()); vec.as_mut_ptr().add(pos).copy_from(buf.as_ptr(), buf.len()); @@ -461,10 +467,14 @@ where /// This also allows for the vec body to be empty, but with a position of N. /// This means that [`Write`] will pad the vec with 0 initially, /// before writing anything from that point -fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result +fn vec_write( + pos_mut: &mut u64, + vec: &mut Vec, + buf: &[u8], +) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { let buf_len = buf.len(); let mut pos = reserve_and_pad(pos_mut, vec, buf_len)?; @@ -500,7 +510,7 @@ fn vec_write_vectored( ) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // For safety reasons, we don't want this sum to overflow ever. // If this saturates, the reserve should panic to avoid any unsound writing. @@ -551,7 +561,7 @@ impl Write for Cursor<&mut [u8]> { impl Write for Cursor<&mut Vec> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, self.inner, buf) @@ -576,7 +586,7 @@ where impl Write for Cursor> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, &mut self.inner, buf) diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index ec3394e0b16c1..8671ebf5c8141 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -379,7 +379,9 @@ impl Write for &mut [u8] { /// The vector will grow as needed. #[stable(feature = "rust1", since = "1.0.0")] impl Write for Vec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { self.extend_from_slice(buf); @@ -416,7 +418,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// Read is implemented for `VecDeque` by consuming bytes from the front of the `VecDeque`. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] impl Read for VecDeque -where [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]: { +where + [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]:, +{ /// Fill `buf` with the contents of the "front" slice as returned by /// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are /// discontiguous, multiple calls to `read` will be needed to read the entire content. @@ -441,7 +445,9 @@ where [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]: { /// Write is implemented for `VecDeque` by appending to the `VecDeque`, growing it as needed. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] impl Write for VecDeque -where [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]: { +where + [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]:, +{ #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { self.extend(buf); diff --git a/library/std/src/sys/unix/thread_local_dtor.rs b/library/std/src/sys/unix/thread_local_dtor.rs index c09b0f7832b6a..4549f5d77742c 100644 --- a/library/std/src/sys/unix/thread_local_dtor.rs +++ b/library/std/src/sys/unix/thread_local_dtor.rs @@ -2,11 +2,11 @@ #![unstable(feature = "thread_local_internals", issue = "none")] #![feature(global_co_alloc_plvec)] -use core::alloc::PlVec; - //! Provides thread-local destructors without an associated "key", which //! can be more efficient. +use core::alloc::PlVec; + // Since what appears to be glibc 2.18 this symbol has been shipped which // GCC and clang both use to invoke destructors in thread_local globals, so // let's do the same! diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 2d956b30e4116..cefe9849b0db5 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -77,7 +77,10 @@ pub(crate) struct Context<'tcx> { // `Context` is cloned a lot, so we don't want the size to grow unexpectedly. #[cfg(all(not(windows), target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(Context<'_>, 160 + 2 * mem::size_of::()); +rustc_data_structures::static_assert_size!( + Context<'_>, + 160 + 2 * mem::size_of::() +); /// Shared mutable state used in [`Context`] and elsewhere. pub(crate) struct SharedContext<'tcx> {