You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnmain(){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!
The text was updated successfully, but these errors were encountered:
The error message pointing to the "{}" is a bit misleading - the temporary value is actually in the code generated by format_args, and the span happens to point to the format string.
Your example expands to this:
fnmain(){let test = &"hello".to_owned();let args = ::std::fmt::Arguments::new_v1_formatted(&[""],&match(&test,){(arg0,) => [::std::fmt::ArgumentV1::new(arg0,::std::fmt::Display::fmt)],},&[::std::fmt::rt::v1::Argument{position:::std::fmt::rt::v1::Position::At(0usize),format:::std::fmt::rt::v1::FormatSpec{fill:' ',align:::std::fmt::rt::v1::Alignment::Unknown,flags:0u32,precision:::std::fmt::rt::v1::Count::Implied,width:::std::fmt::rt::v1::Count::Implied,},}],);}
Building that directly points to the actual code that's the problem:
error[E0597]: borrowed value does not live long enough
--> src/main.rs:7:10
|
7 | &match (&test,) {
| __________^
8 | | (arg0,) => [::std::fmt::ArgumentV1::new(arg0, ::std::fmt::Display::fmt)],
9 | | },
| |_________^ temporary value does not live long enough
...
20 | );
| - temporary value dropped here while still borrowed
21 | }
| - temporary value needs to live until here
|
= note: consider using a `let` binding to increase its lifetime
This code:
returns this error:
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 alog::Record
. This with 1.27.0.Thanks!
The text was updated successfully, but these errors were encountered: