I understand that when a variable whose type implements Drop falls outside the scope, a function call fn drop(&mut self) is inserted and a newly created mutable reference to the variable leaving the scope is passed.
However, how is this possible in cases where a variable is immutable, and it would be illegal to borrow it with variability? Here is an example of what I am saying:
fn main() { let x = vec![1, 2, 3]; let y = &mut x; }
Which causes the following error: cannot take the immutable local variable x as mutable as expected.
Something similar should happen when x is dropped because Drop expecting a volatile link.
source share