Skip to content

Using format_args!() to build a fmt::Arguments fails to compile #51905

@agrover

Description

@agrover

This code:

fn main() {
    let test = &"hello".to_owned();
    let args = format_args!("{}", test);
}

returns this error:

6 |     let args = format_args!("{}", test);
  |                             ^^^^       - temporary value dropped here while still borrowed
  |                             |
  |                             temporary value does not live long enough
7 | }
  | - temporary value needs to live until here
  |
  = note: consider using a `let` binding to increase its lifetime

This makes no sense to me. Doesn't "{}" have a static lifetime?

btw this is related to rust-lang/log#282, I'm trying to recreate a fmt::Arguments to build a log::Record. This with 1.27.0.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions