Skip to content

Commit 047bd61

Browse files
Merge pull request #3622 from TheBlueMatt/2025-02-legacy-move-semantics
Avoid accessing `legacy` TLV fields after the TLV-stream read
2 parents 1610854 + 0452241 commit 047bd61

File tree

2 files changed

+4
-25
lines changed

2 files changed

+4
-25
lines changed

lightning-macros/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ pub fn skip_legacy_fields(expr: TokenStream) -> TokenStream {
246246
/// Is expected to wrap a struct definition like
247247
/// ```ignore
248248
/// drop_legacy_field_definition!(Self {
249-
/// field1: $crate::_ignore_arg!(field1, option),
250-
/// field2: $crate::_ignore_arg!(field2, (legacy, u64, {})),
249+
/// field1: $crate::_init_tlv_based_struct_field!(field1, option),
250+
/// field2: $crate::_init_tlv_based_struct_field!(field2, (legacy, u64, {})),
251251
/// })
252252
/// ```
253253
/// and will drop fields defined like `field2` with a type starting with `legacy`.
@@ -277,7 +277,7 @@ pub fn drop_legacy_field_definition(expr: TokenStream) -> TokenStream {
277277
for field in new_fields {
278278
if let syn::Expr::Macro(syn::ExprMacro { mac, .. }) = &field.expr {
279279
let macro_name = mac.path.segments.last().unwrap().ident.to_string();
280-
let is_init = macro_name == "_ignore_arg";
280+
let is_init = macro_name == "_init_tlv_based_struct_field";
281281
// Skip `field_name` and `:`, giving us just the type's group
282282
let ty_tokens = mac.tokens.clone().into_iter().skip(2).next();
283283
if let Some(proc_macro2::TokenTree::Group(group)) = ty_tokens {

lightning/src/util/ser_macros.rs

+1-22
Original file line numberDiff line numberDiff line change
@@ -894,17 +894,6 @@ macro_rules! _init_and_read_tlv_stream {
894894
}
895895
}
896896

897-
/// Dummy macro that drops the second argument (which is used by
898-
/// [`lightning_macros::drop_legacy_field_definition`] to match for legacy fields but isn't needed
899-
/// in the final code we want to generate).
900-
#[doc(hidden)]
901-
#[macro_export]
902-
macro_rules! _ignore_arg {
903-
($field: ident, $fieldty: tt) => {
904-
$field
905-
};
906-
}
907-
908897
/// Reads a TLV stream with the given fields to build a struct/enum variant of type `$thing`
909898
#[doc(hidden)]
910899
#[macro_export]
@@ -913,18 +902,8 @@ macro_rules! _decode_and_build {
913902
$crate::_init_and_read_len_prefixed_tlv_fields!($stream, {
914903
$(($type, $field, $fieldty)),*
915904
});
916-
// rustc is kinda dumb about unused variable warnings when we declare a variable via an
917-
// ident in a macro and then use it in an expr also defined in the same macro call. Thus,
918-
// it may generate unused variable warnings for variables that are, in fact, very much
919-
// used. Instead, we just blanket ignore unused variables here as it may be useful to write
920-
// field names without a _ prefix for legacy fields even if we don't care about the read
921-
// value.
922-
$(
923-
#[allow(unused_variables)]
924-
let $field = $crate::_init_tlv_based_struct_field!($field, $fieldty);
925-
)*
926905
::lightning_macros::drop_legacy_field_definition!($thing {
927-
$($field: $crate::_ignore_arg!($field, $fieldty)),*
906+
$($field: $crate::_init_tlv_based_struct_field!($field, $fieldty)),*
928907
})
929908
} }
930909
}

0 commit comments

Comments
 (0)