From: Duncan Dean Date: Fri, 6 Sep 2024 10:26:19 +0000 (+0200) Subject: Add an `explicit_type` TLV syntax for avoiding certain cases of type inference X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=c0d84e85c7f1af37882087f6a798ef7d1bc5c52b;p=rust-lightning Add an `explicit_type` TLV syntax for avoiding certain cases of type inference 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# --- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 96dde1b5a..2fa556c95 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index d543142e1..0a18b5aac 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -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), }); diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs index 178fb947a..d4428697b 100644 --- a/lightning/src/util/ser_macros.rs +++ b/lightning/src/util/ser_macros.rs @@ -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> = $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); };