Fix temporary value lifetime in serialize_struct
Before adoption: this commit came in with the history the project adopted, so no landing records it.
In the 2024 edition of Rust, `serde`s macros for `serialize_with` can lead to a temporary lifetime error such as: ``` error[E0716]: temporary value dropped while borrowed --> my-binary/src/main.rs:6:10 | 6 | #[derive(MyDerive)] | ^^^^^^^- | | | | | temporary value is freed at the end of this statement | creates a temporary value which is freed while still in use | borrow later used by call | in this derive macro expansion | ::: /private/tmp/life/my-project/my-macro/src/lib.rs:6:1 | 6 | pub fn my_derive(_input: TokenStream) -> TokenStream { | ---------------------------------------------------- in this expansion of `#[derive(MyDerive)]` | = note: consider using a `let` binding to create a longer lived value ``` This is because the macro code takes a reference to struct inside of a block, which then goes out of scope when `serde` passes it to a function. To resolve this, we move the reference to outside of the block, to ensure that the lifetime extends into the function call.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Signed-off-by: Andrew V. Teylu <andrew.teylu@vector.com>
Diff stats
1 file+2 added−2 removed
- other:+2 added−2 removed