]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0745.md
Clean up E0745
[rust.git] / src / librustc_error_codes / error_codes / E0745.md
1 The address of temporary value was taken.
2
3 Erroneous code example:
4
5 ```compile_fail,E0745
6 # #![feature(raw_ref_op)]
7 fn temp_address() {
8     let ptr = &raw const 2; // error!
9 }
10 ```
11
12 In this example, `2` is destroyed right after the assignment, which means that
13 `ptr` now points to an unavailable location.
14
15 To avoid this error, first bind the temporary to a named local variable:
16
17 ```
18 # #![feature(raw_ref_op)]
19 fn temp_address() {
20     let val = 2;
21     let ptr = &raw const val; // ok!
22 }
23 ```