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

format_args appears to be unusable #42253

Closed
Mark-Simulacrum opened this Issue May 26, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@Mark-Simulacrum
Member

Mark-Simulacrum commented May 26, 2017

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)],
                                       });
}
@sfackler

This comment has been minimized.

Show comment
Hide comment
@sfackler

sfackler May 27, 2017

Member

format_args! works fine as long as the value is passed directly into whatever's going to consume the fmt::Arguments.

Member

sfackler commented May 27, 2017

format_args! works fine as long as the value is passed directly into whatever's going to consume the fmt::Arguments.

@Mark-Simulacrum

This comment has been minimized.

Show comment
Hide comment
@Mark-Simulacrum

Mark-Simulacrum May 27, 2017

Member

Could you give an example? I'm not quite sure I follow.

Member

Mark-Simulacrum commented May 27, 2017

Could you give an example? I'm not quite sure I follow.

@Mark-Simulacrum

This comment has been minimized.

Show comment
Hide comment
@Mark-Simulacrum

Mark-Simulacrum May 27, 2017

Member

Hm, okay. I'll close this then; I don't think we need to do anything in that case.

Member

Mark-Simulacrum commented May 27, 2017

Hm, okay. I'll close this then; I don't think we need to do anything in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment