]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add an `explicit_type` TLV syntax for avoiding certain cases of type inference
authorDuncan Dean <git@dunxen.dev>
Fri, 6 Sep 2024 10:26:19 +0000 (12:26 +0200)
committerDuncan Dean <git@dunxen.dev>
Wed, 2 Oct 2024 11:08:04 +0000 (13:08 +0200)
This new syntax is used to fix "dependency on fallback of ! -> ()".
This avoids 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#

.github/workflows/build.yml
lightning/src/ln/chan_utils.rs
lightning/src/util/ser_macros.rs

index 96dde1b5a23c3e9066024201f3051039ed9f345b..2fa556c95ee773ec7a38e3110b92367deabea86a 100644 (file)
@@ -335,8 +335,7 @@ jobs:
                 -A clippy::unnecessary_to_owned \
                 -A clippy::unnecessary_unwrap \
                 -A clippy::unused_unit \
-                -A clippy::useless_conversion \
-                -A dependency_on_unit_never_type_fallback
+                -A clippy::useless_conversion
 
   rustfmt:
     runs-on: ubuntu-latest
index d543142e1ab35e2efce52897a900af4905bb23ff..0a18b5aac37ad7b7d27a0abbbcc5f07e11368487 100644 (file)
@@ -1412,7 +1412,7 @@ impl Readable for CommitmentTransaction {
                        (8, keys, required),
                        (10, built, required),
                        (12, htlcs, required_vec),
-                       (14, _legacy_deserialization_prevention_marker, option),
+                       (14, _legacy_deserialization_prevention_marker, (option, explicit_type: ())),
                        (15, channel_type_features, option),
                });
 
index 178fb947aa1ac0ea7f87472ec6052da99d2b7879..d4428697b4d5b194a207598f43f7f4fc9293b037 100644 (file)
@@ -281,6 +281,12 @@ macro_rules! _check_decoded_tlv_order {
        ($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, option) => {{
                // no-op
        }};
+       ($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (option, explicit_type: $fieldty: ty)) => {{
+               // no-op
+       }};
+       ($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
+               _check_decoded_tlv_order!($last_seen_type, $typ, $type, $field, required);
+       }};
        ($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, required_vec) => {{
                $crate::_check_decoded_tlv_order!($last_seen_type, $typ, $type, $field, required);
        }};
@@ -332,6 +338,12 @@ macro_rules! _check_missing_tlv {
        ($last_seen_type: expr, $type: expr, $field: ident, option) => {{
                // no-op
        }};
+       ($last_seen_type: expr, $type: expr, $field: ident, (option, explicit_type: $fieldty: ty)) => {{
+               // no-op
+       }};
+       ($last_seen_type: expr, $type: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
+               _check_missing_tlv!($last_seen_type, $type, $field, required);
+       }};
        ($last_seen_type: expr, $type: expr, $field: ident, optional_vec) => {{
                // no-op
        }};
@@ -372,6 +384,14 @@ macro_rules! _decode_tlv {
        ($outer_reader: expr, $reader: expr, $field: ident, option) => {{
                $field = Some($crate::util::ser::Readable::read(&mut $reader)?);
        }};
+       ($outer_reader: expr, $reader: expr, $field: ident, (option, explicit_type: $fieldty: ty)) => {{
+               let _field: &Option<$fieldty> = &$field;
+               _decode_tlv!($outer_reader, $reader, $field, option);
+       }};
+       ($outer_reader: expr, $reader: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
+               let _field: &$fieldty = &$field;
+               _decode_tlv!($outer_reader, $reader, $field, required);
+       }};
        ($outer_reader: expr, $reader: expr, $field: ident, optional_vec) => {{
                let f: $crate::util::ser::WithoutLength<Vec<_>> = $crate::util::ser::Readable::read(&mut $reader)?;
                $field = Some(f.0);
@@ -795,6 +815,12 @@ macro_rules! _init_tlv_field_var {
        ($field: ident, optional_vec) => {
                let mut $field = Some(Vec::new());
        };
+       ($field: ident, (option, explicit_type: $fieldty: ty)) => {
+               let mut $field: Option<$fieldty> = None;
+       };
+       ($field: ident, (required, explicit_type: $fieldty: ty)) => {
+               let mut $field = $crate::util::ser::RequiredWrapper::<$fieldty>(None);
+       };
        ($field: ident, (option, encoding: ($fieldty: ty, $encoding: ident))) => {
                $crate::_init_tlv_field_var!($field, option);
        };