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

borrow error gives unhelpful let binding suggestion #114374

Closed
euclio opened this issue Aug 2, 2023 · 1 comment · Fixed by #114511
Closed

borrow error gives unhelpful let binding suggestion #114374

euclio opened this issue Aug 2, 2023 · 1 comment · Fixed by #114511
Assignees
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

@euclio
Copy link
Contributor

euclio commented Aug 2, 2023

Code

fn bar<'a>(_: std::fmt::Arguments<'a>) {
    
}

fn main() {
    let foo = format_args!("{}", "hi");
    
    bar(foo);
}

Current output

error[E0716]: temporary value dropped while borrowed
 --> src/main.rs:6:15
  |
6 |     let foo = format_args!("{}", "hi");
  |               ^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
  |               |
  |               creates a temporary value which is freed while still in use
7 |     
8 |     bar(foo);
  |         --- borrow later used here
  |
  = note: this error originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider using a `let` binding to create a longer lived value
  |
6 ~     let binding = format_args!("{}", "hi");
7 ~     let foo = binding;
  |

For more information about this error, try `rustc --explain E0716`.

Desired output

error[E0716]: temporary value dropped while borrowed
 --> src/main.rs:6:15
  |
6 |     let foo = format_args!("{}", "hi");
  |               ^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
  |               |
  |               creates a temporary value which is freed while still in use
7 |     
8 |     bar(foo);
  |         --- borrow later used here
  |
  = note: this error originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

Rationale and extra context

The binding suggestion is not helpful, attempting to use it will just create the same error with the same suggestion.

Other cases

No response

Anything else?

No response

@euclio euclio 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 Aug 2, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 2, 2023
@chenyukang chenyukang self-assigned this Aug 5, 2023
@fmease

This comment was marked as resolved.

@rustbot rustbot removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 10, 2023
@bors bors closed this as completed in b046541 Sep 6, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 6, 2023
Rollup merge of rust-lang#114511 - chenyukang:yukang-fix-114374-fmt-args, r=b-naber

Remove the unhelpful let binding diag comes from FormatArguments

Fixes rust-lang#114374
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

Successfully merging a pull request may close this issue.

4 participants