Skip to content

format_args appears to be unusable #42253

Closed
@Mark-Simulacrum

Description

@Mark-Simulacrum

This appears to reproduce across stable/beta/nightly, and basically makes format_args! unusable as far as I can tell. Nothing I've managed to pass in has compiled, though I have not experimented extensively. I've also included the expanded code (rustc -Zunstable-options --pretty=expanded) which shows why this is the case.

fn a() {
    let a = 10;
    let msg = format_args!("{}", a);
}

fails with:

error: borrowed value does not live long enough
 --> test.rs:3:36
  |
3 |     let msg = format_args!("{}", a);
  |                            ----    ^ temporary value dropped here while still borrowed
  |                            |
  |                            temporary value created here
4 | }
  | - temporary value needs to live until here
  |
  = note: consider using a `let` binding to increase its lifetime

expanded:

fn a() {
    let a = 10;
    let msg =
        ::std::fmt::Arguments::new_v1({
                                          static __STATIC_FMTSTR:
                                                 &'static [&'static str] =
                                              &[""];
                                          __STATIC_FMTSTR
                                      },
                                      &match (&a,) { // I believe the problem is here
                                           (__arg0,) =>
                                           [::std::fmt::ArgumentV1::new(__arg0,
                                                                        ::std::fmt::Display::fmt)],
                                       });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-syntaxextArea: Syntax extensionsT-libs-apiRelevant to the library API 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