Skip to content

Commit 1d3abf1

Browse files
committed
Tutorial: clarify 'other uses of safe references'
1 parent 3e52a0a commit 1d3abf1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

doc/tutorial.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,6 +1859,13 @@ match my_rec {
18591859
}
18601860
~~~~
18611861

1862+
It's unsafe to dereference `b` in the second `log` expression, because `b` is
1863+
a _pointer_ to the inside of `my_rec`, and the assignment statement has
1864+
allocated a new record and assigned `my_rec` to point to it. Thus, the old
1865+
contents of `my_rec` are no longer live, and `b` is dangling at this point.
1866+
The borrow-checking analysis inside the compiler recognizes this situation
1867+
and rejects the program.
1868+
18621869
## Argument passing styles
18631870

18641871
The fact that arguments are conceptually passed by safe reference does

0 commit comments

Comments
 (0)