The following code compiles if the vector type is Vec but does not compile if it uses Smallvec. What trick is used in Vec to allow dropping elements without causing a borrow error? Is it a language hack?
pub type V<T> = Vec<T>;
struct C<T>(V<T>);
impl<T> C<T> {
pub fn push(&mut self, bytes: T) {
self.0.push(bytes);
}
}
let mut a = [Dropable];
pub struct Dropable;
impl Drop for Dropable {
fn drop(&mut self) {
info!("drop called");
}
}
pub fn process<T>(c: &mut V<T>) {
c.clear();
}
let mut c = C(V::<_>::new());
c.push(&a);
process(&mut c.0);
a[0] = Dropable;