Skip to content

Commit daf179a

Browse files
committed
Add an option_unit TLV type to fix dependency on fallback of ! -> ()
This is needed to avoid cases where code compiles with a fallback of the never type leading to the unit type. The behaviour in Rust edition 2024 would make this a compile error. See: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/builtin/static.DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK.html#
1 parent d35239c commit daf179a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 1 addition & 1 deletion
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_unit),
14161416
(15, channel_type_features, option),
14171417
});
14181418

lightning/src/util/ser_macros.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ 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_unit) => {{
285+
// no-op
286+
}};
284287
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, required_vec) => {{
285288
$crate::_check_decoded_tlv_order!($last_seen_type, $typ, $type, $field, required);
286289
}};
@@ -332,6 +335,9 @@ macro_rules! _check_missing_tlv {
332335
($last_seen_type: expr, $type: expr, $field: ident, option) => {{
333336
// no-op
334337
}};
338+
($last_seen_type: expr, $type: expr, $field: ident, option_unit) => {{
339+
// no-op
340+
}};
335341
($last_seen_type: expr, $type: expr, $field: ident, optional_vec) => {{
336342
// no-op
337343
}};
@@ -372,6 +378,9 @@ macro_rules! _decode_tlv {
372378
($outer_reader: expr, $reader: expr, $field: ident, option) => {{
373379
$field = Some($crate::util::ser::Readable::read(&mut $reader)?);
374380
}};
381+
($outer_reader: expr, $reader: expr, $field: ident, option_unit) => {{
382+
$field = Some($crate::util::ser::Readable::read(&mut $reader)?);
383+
}};
375384
($outer_reader: expr, $reader: expr, $field: ident, optional_vec) => {{
376385
let f: $crate::util::ser::WithoutLength<Vec<_>> = $crate::util::ser::Readable::read(&mut $reader)?;
377386
$field = Some(f.0);
@@ -792,6 +801,9 @@ macro_rules! _init_tlv_field_var {
792801
($field: ident, option) => {
793802
let mut $field = None;
794803
};
804+
($field: ident, option_unit) => {
805+
let mut $field: Option<()> = None;
806+
};
795807
($field: ident, optional_vec) => {
796808
let mut $field = Some(Vec::new());
797809
};

0 commit comments

Comments
 (0)