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
let res = rt_format!(file_tpl, id);match res {//...}
and I'm getting following error (with -Z external-macro-backtrace):
error[E0716]: temporary value dropped while borrowed
--> <::runtime_fmt::macros::rt_format_args macros>:22:44
|
1 | / (
2 | | @ [ $ spec : expr ] [ $ ( $ args : tt ) * ] $ name : tt = $ e : expr , $ (
3 | | $ rest : tt ) * ) => {
4 | | rt_format_args ! (
... |
19 | / rt_format_args ! (
20 | | @ [ $ spec ] [ $ ( $ args ) * $ crate :: Param :: normal ( & $ e ) , ] ) } ; (
| |___________________________________________________________________________- in this macro invocation (#4)
21 | @ [ $ spec : expr ] [ $ ( $ args : tt ) * ] ) => {
22 | | $ crate :: FormatBuf :: new ( & $ spec , & [ $ ( $ args ) * ] ) } ; (
| | ^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
23 | | $ spec : expr , $ ( $ rest : tt ) * ) => {
24 | | rt_format_args ! ( @ [ $ spec ] [ ] $ ( $ rest ) * ) } ; ( $ spec : expr ) =>
| | -----------------------------------------------------
| | |
| | in this macro invocation (#3)
25 | | { $ crate :: FormatBuf :: new ( & $ spec , & [ ] ) } ;
| | -
| | |
| | in this expansion of `rt_format_args!` (#2)
| |__________________________________________________________in this expansion of `rt_format_args!` (#3)
| in this expansion of `rt_format_args!` (#4)
|
::: tt/src/cfg.rs:77:51
|
77 | let res = rt_format!(file_tpl, id);
| ------------------------- temporary value is freed at the end of this statement
| |
| in this macro invocation (#1)
78 | match res {
| --- borrow later used here
|
::: <::runtime_fmt::macros::rt_format macros>:1:1
|
1 | / ( $ ( $ rest : tt ) * ) => {
2 | | rt_format_args ! ( $ ( $ rest ) * ) . map (
| | -----------------------------------
| | |
| | in this macro invocation (#2)
3 | | | x | x . with ( :: std :: fmt :: format ) ) }
| |______________________________________________- in this expansion of `rt_format!` (#1)
|
= note: consider using a `let` binding to create a longer lived value
Some additional points:
explicit reborrow doesn't fix error
but transforming possible error into e.g. String (via rt_format!(...).map_err(|e| e.to_string())) fixes
So, AFAIU, during invokation of macro, temporary string is created, and lifetime of error is bound to that temporary.
The text was updated successfully, but these errors were encountered:
MikailBag
changed the title
rt_format! doesn't work
rt_format! returns error which refers on temprorary data
Jun 3, 2019
Hello!
I'm using your library like this:
and I'm getting following error (with -Z external-macro-backtrace):
Some additional points:
rt_format!(...).map_err(|e| e.to_string())
) fixesSo, AFAIU, during invokation of macro, temporary string is created, and lifetime of error is bound to that temporary.
The text was updated successfully, but these errors were encountered: