use core::marker::PhantomData;
use core::mem;
#[cfg(not(test))]
+#[cfg(stage0)]
use core::num::Float;
use core::ops::Bound::{Excluded, Included, Unbounded};
use core::ops::{Index, IndexMut, RangeBounds};
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
- pub fn new() -> Vec<T> {
+ pub const fn new() -> Vec<T> {
Vec {
- buf: RawVec::new(),
+ buf: RawVec::empty(),
len: 0,
}
}
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn shrink_to_fit(&mut self) {
- self.buf.shrink_to_fit(self.len);
+ if self.capacity() != self.len {
+ self.buf.shrink_to_fit(self.len);
+ }
}
/// Shrinks the capacity of the vector with a lower bound.
impl<'a, T> Drop for Drain<'a, T> {
fn drop(&mut self) {
// exhaust self first
- while let Some(_) = self.next() {}
+ self.for_each(drop);
if self.tail_len > 0 {
unsafe {
#[stable(feature = "vec_splice", since = "1.21.0")]
impl<'a, I: Iterator> Drop for Splice<'a, I> {
fn drop(&mut self) {
- // exhaust drain first
- while let Some(_) = self.drain.next() {}
-
+ self.drain.by_ref().for_each(drop);
unsafe {
if self.drain.tail_len == 0 {
where F: FnMut(&mut T) -> bool,
{
fn drop(&mut self) {
- for _ in self.by_ref() { }
-
+ self.for_each(drop);
unsafe {
self.vec.set_len(self.old_len - self.del);
}