@@ -178,6 +178,8 @@ pub struct BTreeMap<
178
178
length : usize ,
179
179
/// `ManuallyDrop` to control drop order (needs to be dropped after all the nodes).
180
180
pub ( super ) alloc : ManuallyDrop < A > ,
181
+ // For dropck; the `Box` avoids making the `Unpin` impl more strict than before
182
+ _marker : PhantomData < crate :: boxed:: Box < ( K , V ) > > ,
181
183
}
182
184
183
185
#[ stable( feature = "btree_drop" , since = "1.7.0" ) ]
@@ -187,6 +189,19 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V, A: Allocator + Clone> Drop for BTr
187
189
}
188
190
}
189
191
192
+ // FIXME: This implementation is "wrong", but changing it would be a breaking change.
193
+ // (The bounds of the automatic `UnwindSafe` implementation have been like this since Rust 1.50.)
194
+ // Maybe we can fix it nonetheless with a crater run, or if the `UnwindSafe`
195
+ // traits are deprecated, or disarmed (no longer causing hard errors) in the future.
196
+ #[ stable( feature = "btree_unwindsafe" , since = "1.64.0" ) ]
197
+ impl < K , V , A : Allocator + Clone > core:: panic:: UnwindSafe for BTreeMap < K , V , A >
198
+ where
199
+ A : core:: panic:: UnwindSafe ,
200
+ K : core:: panic:: RefUnwindSafe ,
201
+ V : core:: panic:: RefUnwindSafe ,
202
+ {
203
+ }
204
+
190
205
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
191
206
impl < K : Clone , V : Clone , A : Allocator + Clone > Clone for BTreeMap < K , V , A > {
192
207
fn clone ( & self ) -> BTreeMap < K , V , A > {
@@ -204,6 +219,7 @@ impl<K: Clone, V: Clone, A: Allocator + Clone> Clone for BTreeMap<K, V, A> {
204
219
root : Some ( Root :: new ( alloc. clone ( ) ) ) ,
205
220
length : 0 ,
206
221
alloc : ManuallyDrop :: new ( alloc) ,
222
+ _marker : PhantomData ,
207
223
} ;
208
224
209
225
{
@@ -567,7 +583,7 @@ impl<K, V> BTreeMap<K, V> {
567
583
#[ rustc_const_unstable( feature = "const_btree_new" , issue = "71835" ) ]
568
584
#[ must_use]
569
585
pub const fn new ( ) -> BTreeMap < K , V > {
570
- BTreeMap { root : None , length : 0 , alloc : ManuallyDrop :: new ( Global ) }
586
+ BTreeMap { root : None , length : 0 , alloc : ManuallyDrop :: new ( Global ) , _marker : PhantomData }
571
587
}
572
588
}
573
589
@@ -593,6 +609,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
593
609
root : mem:: replace ( & mut self . root , None ) ,
594
610
length : mem:: replace ( & mut self . length , 0 ) ,
595
611
alloc : self . alloc . clone ( ) ,
612
+ _marker : PhantomData ,
596
613
} ) ;
597
614
}
598
615
@@ -615,7 +632,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
615
632
/// ```
616
633
#[ unstable( feature = "btreemap_alloc" , issue = "32838" ) ]
617
634
pub fn new_in ( alloc : A ) -> BTreeMap < K , V , A > {
618
- BTreeMap { root : None , length : 0 , alloc : ManuallyDrop :: new ( alloc) }
635
+ BTreeMap { root : None , length : 0 , alloc : ManuallyDrop :: new ( alloc) , _marker : PhantomData }
619
636
}
620
637
}
621
638
@@ -1320,7 +1337,12 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
1320
1337
let ( new_left_len, right_len) = Root :: calc_split_length ( total_num, & left_root, & right_root) ;
1321
1338
self . length = new_left_len;
1322
1339
1323
- BTreeMap { root : Some ( right_root) , length : right_len, alloc : self . alloc . clone ( ) }
1340
+ BTreeMap {
1341
+ root : Some ( right_root) ,
1342
+ length : right_len,
1343
+ alloc : self . alloc . clone ( ) ,
1344
+ _marker : PhantomData ,
1345
+ }
1324
1346
}
1325
1347
1326
1348
/// Creates an iterator that visits all elements (key-value pairs) in
@@ -1445,7 +1467,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
1445
1467
let mut root = Root :: new ( alloc. clone ( ) ) ;
1446
1468
let mut length = 0 ;
1447
1469
root. bulk_push ( DedupSortedIter :: new ( iter. into_iter ( ) ) , & mut length, alloc. clone ( ) ) ;
1448
- BTreeMap { root : Some ( root) , length, alloc : ManuallyDrop :: new ( alloc) }
1470
+ BTreeMap { root : Some ( root) , length, alloc : ManuallyDrop :: new ( alloc) , _marker : PhantomData }
1449
1471
}
1450
1472
}
1451
1473
0 commit comments