Skip to content

Commit 4e85201

Browse files
committed
Emit both E0385 and E0505. Work with 2015/2018 edition
1 parent d960310 commit 4e85201

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/scope/borrow.md

+14-7
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,21 @@ fn main() {
2929
borrow_i32(&boxed_i32);
3030
borrow_i32(&stacked_i32);
3131
32-
// Take a reference to the data contained inside the box
33-
let _ref_to_i32: &i32 = &boxed_i32;
32+
{
33+
// Take a reference to the data contained inside the box
34+
let _ref_to_i32: &i32 = &boxed_i32;
3435
35-
// Can't destroy `boxed_i32` while the inner value is borrowed later in scope.
36-
eat_box_i32(boxed_i32);
37-
// FIXME ^ Comment out this line
36+
// Error!
37+
// Can't destroy `boxed_i32` while the inner value is borrowed later in scope.
38+
eat_box_i32(boxed_i32);
39+
// FIXME ^ Comment out this line
40+
41+
// Attempt to borrow `_ref_to_i32` after inner value is destroyed
42+
borrow_i32(_ref_to_i32);
43+
// `_ref_to_i32` goes out of scope and is no longer borrowed.
44+
}
3845
39-
// Attempt to borrow `_ref_to_i32` after inner value is destroyed
40-
borrow_i32(_ref_to_i32);
46+
// `boxed_i32` can now give up ownership to `eat_box` and be destroyed
47+
eat_box_i32(boxed_i32);
4148
}
4249
```

0 commit comments

Comments
 (0)