From 85de6489851d4f469c5b382d2ad85705d6346741 Mon Sep 17 00:00:00 2001 From: Pablo Couto Date: Sat, 1 Jul 2017 16:51:34 +0200 Subject: [PATCH] Update compiler output --- src/dropck.md | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/dropck.md b/src/dropck.md index 3903969..f1fef35 100644 --- a/src/dropck.md +++ b/src/dropck.md @@ -80,24 +80,18 @@ fn main() { ``` ```text -:12:28: 12:32 error: `days` does not live long enough -:12 inspector = Inspector(&days); - ^~~~ -:9:11: 15:2 note: reference must be valid for the block at 9:10... -:9 fn main() { -:10 let (inspector, days); -:11 days = Box::new(1); -:12 inspector = Inspector(&days); -:13 // Let's say `days` happens to get dropped first. -:14 // Then when Inspector is dropped, it will try to read free'd memory! - ... -:10:27: 15:2 note: ...but borrowed value is only valid for the block suffix following statement 0 at 10:26 -:10 let (inspector, days); -:11 days = Box::new(1); -:12 inspector = Inspector(&days); -:13 // Let's say `days` happens to get dropped first. -:14 // Then when Inspector is dropped, it will try to read free'd memory! -:15 } +error: `days` does not live long enough + --> :15:1 + | +12 | inspector = Inspector(&days); + | ---- borrow occurs here +... +15 | } + | ^ `days` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to previous error ``` Implementing Drop lets the Inspector execute some arbitrary code during its