Skip to content

Commit 3a1e114

Browse files
committed
comments explaining why we have and don't have ManuallyDrop
1 parent 901cd3a commit 3a1e114

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

library/alloc/src/collections/btree/map.rs

+3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ pub struct BTreeMap<
175175
> {
176176
root: Option<Root<K, V>>,
177177
length: usize,
178+
/// `ManuallyDrop` to control drop order (needs to be dropped after all the nodes).
178179
pub(super) alloc: ManuallyDrop<A>,
179180
}
180181

@@ -384,6 +385,7 @@ pub struct IntoIter<
384385
> {
385386
range: LazyLeafRange<marker::Dying, K, V>,
386387
length: usize,
388+
/// The BTreeMap will outlive this IntoIter so we don't care about drop order for `alloc`.
387389
alloc: A,
388390
}
389391

@@ -1800,6 +1802,7 @@ pub struct DrainFilter<
18001802
{
18011803
pred: F,
18021804
inner: DrainFilterInner<'a, K, V>,
1805+
/// The BTreeMap will outlive this IntoIter so we don't care about drop order for `alloc`.
18031806
alloc: A,
18041807
}
18051808
/// Most of the implementation of DrainFilter are generic over the type

library/alloc/src/collections/btree/map/entry.rs

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct VacantEntry<
5656
pub(super) handle: Option<Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>>,
5757
pub(super) dormant_map: DormantMutRef<'a, BTreeMap<K, V, A>>,
5858

59+
/// The BTreeMap will outlive this IntoIter so we don't care about drop order for `alloc`.
5960
pub(super) alloc: A,
6061

6162
// Be invariant in `K` and `V`
@@ -81,6 +82,7 @@ pub struct OccupiedEntry<
8182
pub(super) handle: Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, marker::KV>,
8283
pub(super) dormant_map: DormantMutRef<'a, BTreeMap<K, V, A>>,
8384

85+
/// The BTreeMap will outlive this IntoIter so we don't care about drop order for `alloc`.
8486
pub(super) alloc: A,
8587

8688
// Be invariant in `K` and `V`

library/alloc/src/collections/btree/set.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,7 @@ pub struct DrainFilter<
12851285
{
12861286
pred: F,
12871287
inner: super::map::DrainFilterInner<'a, T, ()>,
1288+
/// The BTreeMap will outlive this IntoIter so we don't care about drop order for `alloc`.
12881289
alloc: A,
12891290
}
12901291

0 commit comments

Comments
 (0)