Skip to content

Fix new rustc #[macro_export] warning in doctests #3031

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

Conversation

TheBlueMatt
Copy link
Collaborator

rustc now warns any time a #[macro_export] is used inside a function as it generates surprising results. Because doctests are run inside implicit test functions this means any use of #[macro_export] inside a doctest will now warn. We do this in lightning-custom-message to demonstrated how to use the crate, which now fails to compile.

Here we fix this by adding an fn main() {} to the doctest, which causes doctests to be compiled as freestanding code rather than inside a test function.

Note that while discussing this upstream it came up that rustc is also planning on changing the way doctests are compiled to compile an entire crate's doctests in one go rather than in separate crates, causing doctests to have a shared namespace which may generate future surprising outcomes.

@TheBlueMatt TheBlueMatt added this to the 0.0.123 milestone Apr 30, 2024
@codecov-commenter
Copy link

codecov-commenter commented Apr 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.13%. Comparing base (2b14cc4) to head (c8ddf36).

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3031      +/-   ##
==========================================
- Coverage   89.14%   89.13%   -0.02%     
==========================================
  Files         118      118              
  Lines       97850    97850              
  Branches    97850    97850              
==========================================
- Hits        87230    87214      -16     
- Misses       8376     8386      +10     
- Partials     2244     2250       +6     

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

rustc now warns any time a `#[macro_export]` is used inside a
function as it generates surprising results. Because doctests are
run inside implicit test functions this means any use of
`#[macro_export]` inside a doctest will now warn. We do this in
`lightning-custom-message` to demonstrated how to use the crate,
which now fails to compile.

Here we fix this by adding an `fn main() {}` to the doctest, which
causes doctests to be compiled as freestanding code rather than
inside a test function.

Note that while discussing this upstream it came up that rustc is
also planning on changing the way doctests are compiled to compile
an entire crate's doctests in one go rather than in separate
crates, causing doctests to have a shared namespace which may
generate future surprising outcomes.
@TheBlueMatt TheBlueMatt force-pushed the 2024-04-new-rustc-warning branch from 01cbfd6 to c8ddf36 Compare April 30, 2024 14:13
@valentinewallace valentinewallace merged commit c903698 into lightningdevkit:main Apr 30, 2024
16 checks passed
TheBlueMatt added a commit to TheBlueMatt/rust-lightning that referenced this pull request May 6, 2024
…rustc-warning

Fix new rustc `#[macro_export]` warning in doctests
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.

3 participants