From a4bdfe24c5f83cbb03febdb9ab5fd22414eac05f Mon Sep 17 00:00:00 2001 From: The 8472 Date: Tue, 25 Oct 2022 22:55:04 +0200 Subject: [PATCH] Support allocators in various Default for IntoIter impls Global implements Default so we can use that as bound for all allocators --- library/alloc/src/collections/btree/map.rs | 17 +++++++++++++---- library/alloc/src/collections/btree/set.rs | 5 ++++- library/alloc/src/vec/into_iter.rs | 7 +++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 8c8a459fec9..61db46314b7 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -450,7 +450,10 @@ impl Debug for IntoIter { } #[stable(feature = "default_iters", since = "CURRENT_RUSTC_VERSION")] -impl Default for IntoIter { +impl Default for IntoIter +where + A: Allocator + Default + Clone, +{ /// Creates an empty `btree_map::IntoIter`. /// /// ``` @@ -459,7 +462,7 @@ impl Default for IntoIter { /// assert_eq!(iter.len(), 0); /// ``` fn default() -> Self { - IntoIter { range: Default::default(), length: 0, alloc: Global } + IntoIter { range: Default::default(), length: 0, alloc: Default::default() } } } @@ -2106,7 +2109,10 @@ impl ExactSizeIterator for IntoKeys { impl FusedIterator for IntoKeys {} #[stable(feature = "default_iters", since = "CURRENT_RUSTC_VERSION")] -impl Default for IntoKeys { +impl Default for IntoKeys +where + A: Allocator + Default + Clone, +{ /// Creates an empty `btree_map::IntoKeys`. /// /// ``` @@ -2154,7 +2160,10 @@ impl ExactSizeIterator for IntoValues { impl FusedIterator for IntoValues {} #[stable(feature = "default_iters", since = "CURRENT_RUSTC_VERSION")] -impl Default for IntoValues { +impl Default for IntoValues +where + A: Allocator + Default + Clone, +{ /// Creates an empty `btree_map::IntoValues`. /// /// ``` diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index 5992b814bba..c2233f86667 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -1576,7 +1576,10 @@ impl ExactSizeIterator for IntoIter { impl FusedIterator for IntoIter {} #[stable(feature = "default_iters", since = "CURRENT_RUSTC_VERSION")] -impl Default for IntoIter { +impl Default for IntoIter +where + A: Allocator + Default + Clone, +{ /// Creates an empty `btree_set::IntoIter`. /// /// ``` diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 8fed4a584a3..f6525eb9003 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -348,7 +348,10 @@ impl FusedIterator for IntoIter {} unsafe impl TrustedLen for IntoIter {} #[stable(feature = "default_iters", since = "CURRENT_RUSTC_VERSION")] -impl Default for IntoIter { +impl Default for IntoIter +where + A: Allocator + Default, +{ /// Creates an empty `vec::IntoIter`. /// /// ``` @@ -358,7 +361,7 @@ impl Default for IntoIter { /// assert_eq!(iter.as_slice(), &[]); /// ``` fn default() -> Self { - super::Vec::new().into_iter() + super::Vec::new_in(Default::default()).into_iter() } }