Shadowed variable former value lifetime

Hi everyone,

When the former value of a shadowed variable is removed from the memory?

Thanks and have a nice weekend!

A variable's drop scope doesn't change when it gets shadowed, so, where ever it would have been removed without the shadowing (most frequently the end of the containing block).

Demonstration

If you wanted something else to happen, you could explicitly drop(the_variable) before shadowing.

Documentation

1 Like