-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an explicit_type TLV syntax for avoiding certain cases of type inference #3301
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3301 +/- ##
==========================================
- Coverage 89.66% 89.61% -0.05%
==========================================
Files 126 126
Lines 102676 102750 +74
Branches 102676 102750 +74
==========================================
+ Hits 92062 92081 +19
- Misses 7894 7931 +37
- Partials 2720 2738 +18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
0778913
to
0d7b30d
Compare
I haven't looked for other cases where we can use this syntax to force the type, but if mentioned I can update them in this PR too. |
option_unit
TLV type to fix dependency on fallback of`! -> () There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New syntax LGTM.
0d7b30d
to
a640926
Compare
Edited: Forgot to remove some things. Updated. git diff-tree -U1 0d7b30d 37e73cadiff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs
index 3837e3f1..8ebbac10 100644
--- a/lightning/src/util/ser_macros.rs
+++ b/lightning/src/util/ser_macros.rs
@@ -287,3 +287,3 @@ macro_rules! _check_decoded_tlv_order {
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
- // no-op
+ _check_decoded_tlv_order!($last_seen_type, $typ, $type, $field, required);
}};
@@ -344,3 +344,3 @@ macro_rules! _check_missing_tlv {
($last_seen_type: expr, $type: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
- // no-op
+ _check_missing_tlv!($last_seen_type, $type, $field, required);
}};
@@ -387,6 +387,6 @@ macro_rules! _decode_tlv {
($outer_reader: expr, $reader: expr, $field: ident, (option, explicit_type: $fieldty: ty)) => {{
- $field = Some($crate::util::ser::Readable::read(&mut $reader)?);
+ let field: $fieldty = _decode_tlv!($outer_reader, $reader, $field, option); $field = Some(field);
}};
($outer_reader: expr, $reader: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
- $field = Some($crate::util::ser::Readable::read(&mut $reader)?);
+ let field: $fieldty = _decode_tlv!($outer_reader, $reader, $field, required); $field = field;
}}; |
a640926
to
37e73ca
Compare
…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#
37e73ca
to
8d5d327
Compare
No description provided.