I would like to ask something.
In the following code the function takes a mutable reference to the vector and in its body allocates new memory for the vector.
My question is when the deallocation (call of drop) for the original vector vec![1, 2, 3, 4] will happen?
The drop shouldn't be called at the end of the function because the functions does not take ownership of the vector.
No, that's definitely not the only case when a value can be dropped. For example, you can explicitly mention the name of a variable in the middle of a function in order to drop it.
This is one of the strange things that has to be learned when learning Rust. There is also generic drop routine which does the same thing - drop does nothing with it's argument, the effect is the argument is dropped. The documentation claims "This function is not magic". Some might disagree.