@@ -15,12 +15,6 @@ pub trait VecDrop {
15
15
}
16
16
17
17
impl < T > VecDrop for [ MaybeUninit < T > ] {
18
- unsafe fn drop_with_len ( & mut self , _len : usize ) {
19
- // Case of a view, drop does nothing
20
- }
21
- }
22
-
23
- impl < T , const N : usize > VecDrop for [ MaybeUninit < T > ; N ] {
24
18
unsafe fn drop_with_len ( & mut self , len : usize ) {
25
19
// NOTE(unsafe) avoid bound checks in the slicing operation
26
20
// &mut buffer[..len]
@@ -31,6 +25,12 @@ impl<T, const N: usize> VecDrop for [MaybeUninit<T>; N] {
31
25
}
32
26
}
33
27
28
+ impl < T , const N : usize > VecDrop for [ MaybeUninit < T > ; N ] {
29
+ unsafe fn drop_with_len ( & mut self , len : usize ) {
30
+ VecDrop :: drop_with_len ( self . as_mut_slice ( ) , len)
31
+ }
32
+ }
33
+
34
34
/// <div class="warn">This is private API and should not be used</div>
35
35
pub struct VecInner < B : ?Sized + VecDrop > {
36
36
len : usize ,
@@ -1953,7 +1953,7 @@ mod tests {
1953
1953
1954
1954
use static_assertions:: assert_not_impl_any;
1955
1955
1956
- use crate :: Vec ;
1956
+ use super :: { Vec , VecView } ;
1957
1957
1958
1958
// Ensure a `Vec` containing `!Send` values stays `!Send` itself.
1959
1959
assert_not_impl_any ! ( Vec <* const ( ) , 4 >: Send ) ;
@@ -2014,6 +2014,33 @@ mod tests {
2014
2014
assert_eq ! ( Droppable :: count( ) , 0 ) ;
2015
2015
}
2016
2016
2017
+ #[ test]
2018
+ fn drop_vecview ( ) {
2019
+ droppable ! ( ) ;
2020
+
2021
+ {
2022
+ let v: Vec < Droppable , 2 > = Vec :: new ( ) ;
2023
+ let mut v: Box < VecView < Droppable > > = Box :: new ( v) ;
2024
+ v. push ( Droppable :: new ( ) ) . ok ( ) . unwrap ( ) ;
2025
+ v. push ( Droppable :: new ( ) ) . ok ( ) . unwrap ( ) ;
2026
+ assert_eq ! ( Droppable :: count( ) , 2 ) ;
2027
+ v. pop ( ) . unwrap ( ) ;
2028
+ assert_eq ! ( Droppable :: count( ) , 1 ) ;
2029
+ }
2030
+
2031
+ assert_eq ! ( Droppable :: count( ) , 0 ) ;
2032
+
2033
+ {
2034
+ let v: Vec < Droppable , 2 > = Vec :: new ( ) ;
2035
+ let mut v: Box < VecView < Droppable > > = Box :: new ( v) ;
2036
+ v. push ( Droppable :: new ( ) ) . ok ( ) . unwrap ( ) ;
2037
+ v. push ( Droppable :: new ( ) ) . ok ( ) . unwrap ( ) ;
2038
+ assert_eq ! ( Droppable :: count( ) , 2 ) ;
2039
+ }
2040
+
2041
+ assert_eq ! ( Droppable :: count( ) , 0 ) ;
2042
+ }
2043
+
2017
2044
#[ test]
2018
2045
fn eq ( ) {
2019
2046
let mut xs: Vec < i32 , 4 > = Vec :: new ( ) ;
0 commit comments