]> git.lizzy.rs Git - rust.git/commitdiff
Clean up E0745
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Tue, 4 Aug 2020 11:09:15 +0000 (13:09 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Tue, 4 Aug 2020 11:09:15 +0000 (13:09 +0200)
src/librustc_error_codes/error_codes/E0745.md

index 6595691ce786ca3110da5bcc7bd2a3f890c58803..23ee7af30f418b9e8a940173281cd00772c622b6 100644 (file)
@@ -1,20 +1,23 @@
-Cannot take address of temporary value.
+The address of temporary value was taken.
 
 Erroneous code example:
 
 ```compile_fail,E0745
 # #![feature(raw_ref_op)]
 fn temp_address() {
-    let ptr = &raw const 2;   // ERROR
+    let ptr = &raw const 2; // error!
 }
 ```
 
-To avoid the error, first bind the temporary to a named local variable.
+In this example, `2` is destroyed right after the assignment, which means that
+`ptr` now points to an unavailable location.
+
+To avoid this error, first bind the temporary to a named local variable:
 
 ```
 # #![feature(raw_ref_op)]
 fn temp_address() {
     let val = 2;
-    let ptr = &raw const val;
+    let ptr = &raw const val; // ok!
 }
 ```