File tree 2 files changed +15
-5
lines changed
2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -865,6 +865,8 @@ impl<A: Array> SmallVec<A> {
865
865
866
866
/// Insert multiple elements at position `index`, shifting all following elements toward the
867
867
/// back.
868
+ ///
869
+ /// Note: when the iterator panics, this can leak memory.
868
870
pub fn insert_many < I : IntoIterator < Item = A :: Item > > ( & mut self , index : usize , iterable : I ) {
869
871
let iter = iterable. into_iter ( ) ;
870
872
if index == self . len ( ) {
@@ -2092,19 +2094,27 @@ mod tests {
2092
2094
}
2093
2095
}
2094
2096
2097
+ // These boxes are leaked on purpose by panicking `insert_many`,
2098
+ // so we clean them up manually to appease Miri's leak checker.
2099
+ let mut box1 = Box :: new ( false ) ;
2100
+ let mut box2 = Box :: new ( false ) ;
2101
+
2095
2102
let mut vec: SmallVec < [ PanicOnDoubleDrop ; 0 ] > = vec ! [
2096
2103
PanicOnDoubleDrop {
2097
- dropped: Box :: new ( false ) ,
2104
+ dropped: unsafe { Box :: from_raw ( & mut * box1 ) } ,
2098
2105
} ,
2099
2106
PanicOnDoubleDrop {
2100
- dropped: Box :: new ( false ) ,
2107
+ dropped: unsafe { Box :: from_raw ( & mut * box2 ) } ,
2101
2108
} ,
2102
2109
]
2103
2110
. into ( ) ;
2104
2111
let result = :: std:: panic:: catch_unwind ( move || {
2105
2112
vec. insert_many ( 0 , BadIter ) ;
2106
2113
} ) ;
2107
2114
assert ! ( result. is_err( ) ) ;
2115
+
2116
+ drop ( box1) ;
2117
+ drop ( box2) ;
2108
2118
}
2109
2119
2110
2120
#[ test]
Original file line number Diff line number Diff line change @@ -16,6 +16,6 @@ rustup default "$MIRI_NIGHTLY"
16
16
rustup component add miri
17
17
cargo miri setup
18
18
19
- cargo miri test --verbose -- -Zmiri-ignore-leaks
20
- cargo miri test --verbose --features union -- -Zmiri-ignore-leaks
21
- cargo miri test --verbose --all-features -- -Zmiri-ignore-leaks
19
+ cargo miri test --verbose
20
+ cargo miri test --verbose --features union
21
+ cargo miri test --verbose --all-features
You can’t perform that action at this time.
0 commit comments