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

format_args appears to be unusable #42253

Closed
Mark-Simulacrum opened this issue May 26, 2017 · 5 comments
Closed

format_args appears to be unusable #42253

Mark-Simulacrum opened this issue May 26, 2017 · 5 comments
Labels
A-syntaxext Area: Syntax extensions T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@Mark-Simulacrum
Copy link
Member

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)],
                                       });
}
@Mark-Simulacrum Mark-Simulacrum added A-syntaxext Area: Syntax extensions T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels May 26, 2017
@sfackler
Copy link
Member

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

@Mark-Simulacrum
Copy link
Member Author

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

@Mark-Simulacrum
Copy link
Member Author

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

@piegamesde
Copy link
Contributor

Please reopen. I'd really like to have the option to store fmt::Arguments in a variable without running into these lifetimes issues.

A selection people who ran into this as well:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants