Skip to content
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

Merged

Conversation

dunxen
Copy link
Contributor

@dunxen dunxen commented Sep 6, 2024

No description provided.

Copy link

codecov bot commented Sep 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.72%. Comparing base (c7627df) to head (c0d84e8).
Report is 25 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3301      +/-   ##
==========================================
+ Coverage   89.67%   89.72%   +0.04%     
==========================================
  Files         126      126              
  Lines      103165   103747     +582     
  Branches   103165   103747     +582     
==========================================
+ Hits        92510    93083     +573     
- Misses       7935     7949      +14     
+ Partials     2720     2715       -5     
Flag Coverage Δ
?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dunxen
Copy link
Contributor Author

dunxen commented Sep 22, 2024

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.

@dunxen dunxen changed the title Add an option_unit TLV type to fix dependency on fallback of`! -> () Add an explicit_type TLV syntax for avoiding certain cases of type inference Sep 22, 2024
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New syntax LGTM.

lightning/src/util/ser_macros.rs Outdated Show resolved Hide resolved
lightning/src/util/ser_macros.rs Outdated Show resolved Hide resolved
lightning/src/util/ser_macros.rs Outdated Show resolved Hide resolved
@dunxen
Copy link
Contributor Author

dunxen commented Sep 23, 2024

Edited: Forgot to remove some things. Updated.

git diff-tree -U1 0d7b30d 37e73ca
diff --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;
 	}};

@dunxen dunxen force-pushed the 2024-9-fixnevertypefallback branch 3 times, most recently from c314602 to 100c99a Compare October 1, 2024 08:38
…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#
@dunxen dunxen force-pushed the 2024-9-fixnevertypefallback branch from 100c99a to c0d84e8 Compare October 2, 2024 11:08
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is gonna be really nice to use. Pretty straightforward so just gonna land it.

@TheBlueMatt TheBlueMatt merged commit 605952c into lightningdevkit:main Oct 2, 2024
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants