Logo

Question preview

Shadowing

What this preview is

About this preview

Shadowing is a medium quant interview question on language knowledge in Rust.

Unlock full access to getcracked

Join to unlock this question, detailed solutions, and our complete library of quant finance interview prep.

Understanding variable shadowing and drop order in Rust

This question tests your grasp of Rust's ownership and scoping rules, specifically how the language handles variable shadowing and the order in which values are deallocated. When you redeclare a variable name in the same scope, the previous binding is shadowed—but understanding exactly when and how the old value is dropped is crucial to writing predictable Rust code.

Shadowing differs from reassignment: it creates a new binding that may have a different type, and the old binding's lifetime is affected by where the new one ends. This question rewards precision about Rust's execution model, particularly the interaction between scope, rebinding, and the Drop trait. Getting this wrong can lead to subtle bugs in resource management, especially in code that manages files, locks, or other stateful resources.

  • Variable scope and lexical lifetimes
  • The Drop trait and deallocation order
  • Shadowing vs. reassignment semantics