Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardRustDrop plus move interactionSingle-choice MCQ

This code moves a field out of a struct that has fields needing drop. What is the actual compiler behavior and runtime drop outcome?

struct Item(&'static str); impl Drop for Item { fn drop(&mut self) { println!("drop {}", self.0); } } struct P { a: Item, b: Item } fn main() { let p = P { a: Item("a"), b: Item("b") }; let moved = p.a; }