Skip to content

Commit 605952c

Browse files
authored
Merge pull request lightningdevkit#3301 from dunxen/2024-9-fixnevertypefallback
Add an explicit_type TLV syntax for avoiding certain cases of type inference
2 parents 4147de2 + c0d84e8 commit 605952c

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

.github/workflows/build.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ jobs:
335335
-A clippy::unnecessary_to_owned \
336336
-A clippy::unnecessary_unwrap \
337337
-A clippy::unused_unit \
338-
-A clippy::useless_conversion \
339-
-A dependency_on_unit_never_type_fallback
338+
-A clippy::useless_conversion
340339
341340
rustfmt:
342341
runs-on: ubuntu-latest

lightning/src/ln/chan_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ impl Readable for CommitmentTransaction {
14121412
(8, keys, required),
14131413
(10, built, required),
14141414
(12, htlcs, required_vec),
1415-
(14, _legacy_deserialization_prevention_marker, option),
1415+
(14, _legacy_deserialization_prevention_marker, (option, explicit_type: ())),
14161416
(15, channel_type_features, option),
14171417
});
14181418

lightning/src/util/ser_macros.rs

+26
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ macro_rules! _check_decoded_tlv_order {
281281
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, option) => {{
282282
// no-op
283283
}};
284+
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (option, explicit_type: $fieldty: ty)) => {{
285+
// no-op
286+
}};
287+
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
288+
_check_decoded_tlv_order!($last_seen_type, $typ, $type, $field, required);
289+
}};
284290
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, required_vec) => {{
285291
$crate::_check_decoded_tlv_order!($last_seen_type, $typ, $type, $field, required);
286292
}};
@@ -332,6 +338,12 @@ macro_rules! _check_missing_tlv {
332338
($last_seen_type: expr, $type: expr, $field: ident, option) => {{
333339
// no-op
334340
}};
341+
($last_seen_type: expr, $type: expr, $field: ident, (option, explicit_type: $fieldty: ty)) => {{
342+
// no-op
343+
}};
344+
($last_seen_type: expr, $type: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
345+
_check_missing_tlv!($last_seen_type, $type, $field, required);
346+
}};
335347
($last_seen_type: expr, $type: expr, $field: ident, optional_vec) => {{
336348
// no-op
337349
}};
@@ -372,6 +384,14 @@ macro_rules! _decode_tlv {
372384
($outer_reader: expr, $reader: expr, $field: ident, option) => {{
373385
$field = Some($crate::util::ser::Readable::read(&mut $reader)?);
374386
}};
387+
($outer_reader: expr, $reader: expr, $field: ident, (option, explicit_type: $fieldty: ty)) => {{
388+
let _field: &Option<$fieldty> = &$field;
389+
_decode_tlv!($outer_reader, $reader, $field, option);
390+
}};
391+
($outer_reader: expr, $reader: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
392+
let _field: &$fieldty = &$field;
393+
_decode_tlv!($outer_reader, $reader, $field, required);
394+
}};
375395
($outer_reader: expr, $reader: expr, $field: ident, optional_vec) => {{
376396
let f: $crate::util::ser::WithoutLength<Vec<_>> = $crate::util::ser::Readable::read(&mut $reader)?;
377397
$field = Some(f.0);
@@ -795,6 +815,12 @@ macro_rules! _init_tlv_field_var {
795815
($field: ident, optional_vec) => {
796816
let mut $field = Some(Vec::new());
797817
};
818+
($field: ident, (option, explicit_type: $fieldty: ty)) => {
819+
let mut $field: Option<$fieldty> = None;
820+
};
821+
($field: ident, (required, explicit_type: $fieldty: ty)) => {
822+
let mut $field = $crate::util::ser::RequiredWrapper::<$fieldty>(None);
823+
};
798824
($field: ident, (option, encoding: ($fieldty: ty, $encoding: ident))) => {
799825
$crate::_init_tlv_field_var!($field, option);
800826
};

0 commit comments

Comments
 (0)