Skip to content

Commit d960310

Browse files
committed
Only trigger E505.
A value is referenced. The underlying value is then destroyed. The reference is prevented from being used after the underlying value is destroyed.
1 parent 7868b8f commit d960310

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/scope/borrow.md

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

0 commit comments

Comments
 (0)