]> git.lizzy.rs Git - rust.git/commitdiff
Clarifying deallocation order of resources within same scope
authorChristian Persson <saser@live.se>
Sat, 27 Jun 2015 14:58:18 +0000 (16:58 +0200)
committerChristian Persson <saser@live.se>
Sat, 27 Jun 2015 14:58:18 +0000 (16:58 +0200)
src/doc/trpl/references-and-borrowing.md

index b27db2ab7bea8c0ac120f59b9d3540ee05269159..d1d3063138e7e61228dd82652540ee86452dead2 100644 (file)
@@ -336,7 +336,9 @@ In other words, `y` is only valid for the scope where `x` exists. As soon as
 the borrow ‘doesn’t live long enough’ because it’s not valid for the right
 amount of time.
 
-The same problem occurs when the reference is declared _before_ the variable it refers to:
+The same problem occurs when the reference is declared _before_ the variable it
+refers to. This is because resources within the same scope are freed in the
+opposite order they were declared:
 
 ```rust,ignore
 let y: &i32;
@@ -369,3 +371,6 @@ statement 1 at 3:14
     println!("{}", y);
 }
 ```
+
+In the above example, `y` is declared before `x`, meaning that `y` lives longer
+than `x`, which is not allowed.