Skip to content

Commit f45657d

Browse files
committed
Proposed fix for rustsec/advisory-db#847
1 parent d0382d5 commit f45657d

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

src/lib.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -894,27 +894,10 @@ impl<A: Array> iter::FromIterator<A::Item> for StackVec<A> {
894894

895895
impl<A: Array> Extend<A::Item> for StackVec<A> {
896896
fn extend<I: iter::IntoIterator<Item=A::Item>>(&mut self, iterable: I) {
897-
let mut iter = iterable.into_iter();
898-
let (lower_bound, upper_bound) = iter.size_hint();
899-
let upper_bound = upper_bound.expect("iterable must provide upper bound.");
900-
assert!(self.len() + upper_bound <= self.capacity());
901-
902-
unsafe {
903-
let len = self.len();
904-
let ptr = self.as_mut_ptr().padd(len);
905-
let mut count = 0;
906-
while count < lower_bound {
907-
if let Some(out) = iter.next() {
908-
ptr::write(ptr.padd(count), out);
909-
count += 1;
910-
} else {
911-
break;
912-
}
913-
}
914-
self.set_len(len + count);
915-
}
916-
917-
for elem in iter {
897+
// size_hint() has no safety guarantees, and TrustedLen
898+
// is nightly only, so we can't do any optimizations with
899+
// size_hint.
900+
for elem in iterable.into_iter() {
918901
self.push(elem);
919902
}
920903
}

0 commit comments

Comments
 (0)