File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
src/librustc_error_codes/error_codes Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 1- Cannot take address of temporary value.
1+ The address of temporary value was taken .
22
33Erroneous code example:
44
55``` compile_fail,E0745
66# #![feature(raw_ref_op)]
77fn temp_address() {
8- let ptr = &raw const 2; // ERROR
8+ let ptr = &raw const 2; // error!
99}
1010```
1111
12- To avoid the error, first bind the temporary to a named local variable.
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:
1316
1417```
1518# #![feature(raw_ref_op)]
1619fn temp_address() {
1720 let val = 2;
18- let ptr = &raw const val;
21+ let ptr = &raw const val; // ok!
1922}
2023```
You can’t perform that action at this time.
0 commit comments