Skip to content

borrow error gives unhelpful let binding suggestion #114374

Closed
@euclio

Description

@euclio

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions