Skip to content

Add CI test that #[cfg] tags are from a defined set #2782

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

Merged
merged 1 commit into from
Dec 11, 2023

Conversation

TheBlueMatt
Copy link
Collaborator

Rust is fairly relaxed in checking the validity of arguments passed to #[cfg]. While it should probably be more strict when checking features, it cannot be strict when checking loose cfg tags, because those can be anything and are simply passed to rustc via unconstrained arguments.

Thus, we do it for rustc manually, but scanning all our source and checking that all our cfg tags match a known cfg tag.

Fixes #2184

Rust is fairly relaxed in checking the validity of arguments
passed to #[cfg]. While it should probably be more strict when
checking features, it cannot be strict when checking loose cfg
tags, because those can be anything and are simply passed to rustc
via unconstrained arguments.

Thus, we do it for rustc manually, but scanning all our source and
checking that all our cfg tags match a known cfg tag.

Fixes lightningdevkit#2184
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ec8e0fe) 88.53% compared to head (75c0e06) 88.91%.
Report is 15 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2782      +/-   ##
==========================================
+ Coverage   88.53%   88.91%   +0.38%     
==========================================
  Files         115      115              
  Lines       91011    92817    +1806     
  Branches    91011    92817    +1806     
==========================================
+ Hits        80580    82532    +1952     
+ Misses       8004     7875     -129     
+ Partials     2427     2410      -17     

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

Copy link
Member

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

The new test file looks pretty solid and covers some important ground:

  1. Nested Conditions Handling:
    • The check_cfg_args function adeptly manages nested conditions (e.g., all(...), any(...), and not(...)), elegantly.
  2. Effective Part Splitting:
    • For non-nested conditions, the function efficiently splits parts using commas
  3. Precise Handling of Special Cases:
    • Special cases like features, target_os, and target_pointer_width are properly addressed, ensuring correct formatting and adherence to specified types.
  4. Assertion Rigor:
    • The strategic use of assertions adds a layer of robustness to the function, mitigating potential issues in loop termination, nested condition closure, and the presence of unwanted double quotes.
  5. Tactful Recursion:
    • Recursion is employed judiciously, enhancing the function’s ability to navigate through nested conditions and manage multiple parts systematically.

The test file looks pretty exhaustive to me, and we can go forward with this approach!

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.

CI Test for unknown cfg assertions
4 participants