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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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.61%. Comparing base (66fb520) to head (8d5d327).
Report is 12 commits behind head on main.

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     
Flag Coverage Δ
89.61% <100.00%> (-0.03%) ⬇️

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;
 	}};

…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#
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