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 · 4 comments
Closed

format_args appears to be unusable #42253

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

Comments

@Mark-Simulacrum
Copy link
Member

@Mark-Simulacrum 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
Copy link
Member

@sfackler 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
Copy link
Member Author

@Mark-Simulacrum Mark-Simulacrum commented May 27, 2017

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

@Mark-Simulacrum
Copy link
Member Author

@Mark-Simulacrum 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.