Skip to content

E0716 suggests binding on 1st assign, rather than merge #124274

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

Open
Rudxain opened this issue Apr 23, 2024 · 0 comments
Open

E0716 suggests binding on 1st assign, rather than merge #124274

Rudxain opened this issue Apr 23, 2024 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Rudxain
Copy link
Contributor

Rudxain commented Apr 23, 2024

Code

#[allow(unused)]
fn main() {
    let x = 0;
    let y;
    y = &&x;
    println!("{y}");
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0716]: temporary value dropped while borrowed
 --> src/main.rs:5:10
  |
5 |     y = &&x;
  |          ^^- temporary value is freed at the end of this statement
  |          |
  |          creates a temporary value which is freed while still in use
6 |     println!("{y}");
  |               --- borrow later used here
  |
help: consider using a `let` binding to create a longer lived value
  |
5 ~     let binding = &x;
6 ~     y = &binding;
  |

For more information about this error, try `rustc --explain E0716`.
error: could not compile `playground` (bin "playground") due to 1 previous error

Desired output

Compiling playground v0.0.1 (/playground)
error[E0716]: temporary value dropped while borrowed
 --> src/main.rs:5:10
  |
5 |     y = &&x;
  |          ^^- temporary value is freed at the end of this statement
  |          |
  |          creates a temporary value which is freed while still in use
6 |     println!("{y}");
  |               --- borrow later used here
  |
help: consider using a `let` binding to create a longer lived value
  |
4 ~     let y = &&x;
  |

For more information about this error, try `rustc --explain E0716`.
error: could not compile `playground` (bin "playground") due to 1 previous error

Rationale and extra context

In "Desired output" IDK what's the proper notation to express "delete line 5"

Other cases

No response

Rust Version

Playground
1.79.0-nightly
2024-04-21
fb898629a26e4acec59c

Anything else?

#99430 (comment)

@Rudxain Rudxain added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant