summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_error_codes/src/error_codes/E0745.md
blob: 23ee7af30f418b9e8a940173281cd00772c622b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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!
}
```

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; // ok!
}
```