I think the immutable borrow drops at line 17, but it doesn't. Why? Thanks!
pub trait SomeTrait<'a, K> where K: 'a
{
fn get_key(&'a self) -> K;
}
pub fn some_func<'a, K, T>(
items: &'a mut Vec<T>
)
where
T: SomeTrait<'a, K>,
K: 'a
{
{
for item in items.iter() {
let key = item.get_key(); // immutable borrow occurs here
drop(key) // borrow dropped here
}
};
items.clear(); // cannot borrow `*items` as mutable because it is also borrowed as immutable
}
This comes up from time to time on this forum - you almost never want to borrow self for the lifetime parameter of the type itself. This causes a borrow that essentially freezes the object when mutable borrows are in play. Drop the 'a from the get_key signature.