File tree 1 file changed +11
-4
lines changed
compiler/rustc_data_structures/src
1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,6 @@ impl<T> IdFunctor for Vec<T> {
87
87
// FIXME: We don't really care about panics here and leak
88
88
// far more than we should, but that should be fine for now.
89
89
let len = self . len ( ) ;
90
- let mut error = Ok ( ( ) ) ;
91
90
unsafe {
92
91
self . set_len ( 0 ) ;
93
92
let start = self . as_mut_ptr ( ) ;
@@ -96,16 +95,24 @@ impl<T> IdFunctor for Vec<T> {
96
95
match f ( ptr:: read ( p) ) {
97
96
Ok ( value) => ptr:: write ( p, value) ,
98
97
Err ( err) => {
99
- error = Err ( err) ;
100
- break ;
98
+ // drop all other elements in self
99
+ // (current element was "moved" into the call to f)
100
+ for j in ( 0 ..i) . chain ( i + 1 ..len) {
101
+ let p = start. add ( j) ;
102
+ ptr:: drop_in_place ( p) ;
103
+ }
104
+
105
+ // returning will drop self, releasing the allocation
106
+ // (len is 0 so elements will not be re-dropped)
107
+ return Err ( err) ;
101
108
}
102
109
}
103
110
}
104
111
// Even if we encountered an error, set the len back
105
112
// so we don't leak memory.
106
113
self . set_len ( len) ;
107
114
}
108
- error . map ( | ( ) | self )
115
+ Ok ( self )
109
116
}
110
117
}
111
118
You can’t perform that action at this time.
0 commit comments