mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-23 22:56:54 +01:00
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#
This commit is contained in:
parent
c7627dfd61
commit
c0d84e85c7
3 changed files with 28 additions and 3 deletions
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue