Fix new rustc `#[macro_export]` warning in doctests 2024-04-new-rustc-warning
authorMatt Corallo <git@bluematt.me>
Tue, 30 Apr 2024 13:45:45 +0000 (13:45 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 30 Apr 2024 14:13:12 +0000 (14:13 +0000)
commitc8ddf36f9c90054f2b172f83fd2b06e5c33f440a
treed410afca744ef1c9dca80ed167cd7c18a3344d66
parent2b14cc40a6acf226aafaddd0efe67264c0df706f
Fix new rustc `#[macro_export]` warning in doctests

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.
lightning-custom-message/src/lib.rs