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); } ```