]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_borrowck/diagnostics.rs
Global error explanations improvements
[rust.git] / src / librustc_borrowck / diagnostics.rs
index 29944aaf3673ddcfcf2749af5535fdb42c1e104c..7f6fd9de3d294709957a0e363e4cc5f5d5ee541c 100644 (file)
@@ -26,7 +26,8 @@ fn foo() -> Box<Fn(u32) -> u32> {
 
 Notice that `x` is stack-allocated by `foo()`. By default, Rust captures
 closed-over data by reference. This means that once `foo()` returns, `x` no
-longer exists. An attempt to access `x` within the closure would thus be unsafe.
+longer exists. An attempt to access `x` within the closure would thus be
+unsafe.
 
 Another situation where this might be encountered is when spawning threads:
 
@@ -73,7 +74,14 @@ fn main() {
 ```
 
 To fix this, ensure that any declared variables are initialized before being
-used.
+used. Example:
+
+```
+fn main() {
+    let x: i32 = 0;
+    let y = x; // ok!
+}
+```
 "##,
 
 E0382: r##"
@@ -210,8 +218,8 @@ fn main(){
 **y = 2;
 ```
 
-It can also be fixed by using a type with interior mutability, such as `Cell` or
-`RefCell`:
+It can also be fixed by using a type with interior mutability, such as `Cell`
+or `RefCell`:
 
 ```
 use std::cell::Cell;
@@ -259,8 +267,8 @@ fn foo<F: FnMut()>(f: F) { }
 ```
 
 Alternatively, we can consider using the `Cell` and `RefCell` types to achieve
-interior mutability through a shared reference. Our example's `mutable` function
-could be redefined as below:
+interior mutability through a shared reference. Our example's `mutable`
+function could be redefined as below:
 
 ```
 use std::cell::Cell;