Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up E0745 #75140

Merged
merged 1 commit into from
Aug 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/librustc_error_codes/error_codes/E0745.md
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!
}
```