From 4e85201c4ed990b571146e9e2d0e4f7cf35fb08a Mon Sep 17 00:00:00 2001 From: Alex Gurganus Date: Wed, 20 Feb 2019 01:15:18 -0600 Subject: [PATCH] Emit both E0385 and E0505. Work with 2015/2018 edition --- src/scope/borrow.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/scope/borrow.md b/src/scope/borrow.md index 51407f147c..72c70e736a 100644 --- a/src/scope/borrow.md +++ b/src/scope/borrow.md @@ -29,14 +29,21 @@ fn main() { borrow_i32(&boxed_i32); borrow_i32(&stacked_i32); - // Take a reference to the data contained inside the box - let _ref_to_i32: &i32 = &boxed_i32; + { + // Take a reference to the data contained inside the box + let _ref_to_i32: &i32 = &boxed_i32; - // Can't destroy `boxed_i32` while the inner value is borrowed later in scope. - eat_box_i32(boxed_i32); - // FIXME ^ Comment out this line + // Error! + // Can't destroy `boxed_i32` while the inner value is borrowed later in scope. + eat_box_i32(boxed_i32); + // FIXME ^ Comment out this line + + // Attempt to borrow `_ref_to_i32` after inner value is destroyed + borrow_i32(_ref_to_i32); + // `_ref_to_i32` goes out of scope and is no longer borrowed. + } - // Attempt to borrow `_ref_to_i32` after inner value is destroyed - borrow_i32(_ref_to_i32); + // `boxed_i32` can now give up ownership to `eat_box` and be destroyed + eat_box_i32(boxed_i32); } ```