forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#75140 - GuillaumeGomez:cleanup-e0745, r=pic…
…kfire Clean up E0745 r? @Dylan-DPC
- Loading branch information
Showing
1 changed file
with
7 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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! | ||
} | ||
``` |