Skip to content

macros: improve overall macro hygiene#7997

Merged
Darksonn merged 1 commit intotokio-rs:masterfrom
dybucc:try-join-hygiene
Apr 2, 2026
Merged

macros: improve overall macro hygiene#7997
Darksonn merged 1 commit intotokio-rs:masterfrom
dybucc:try-join-hygiene

Conversation

@dybucc
Copy link
Copy Markdown
Contributor

@dybucc dybucc commented Mar 31, 2026

Motivation

Multiple macro expansions were previously assuming the existence of some
standard library symbols to both be in-scope and referring to the right symbol,
and not only having the same identifier.

Solution

This has now been refactored into using reexports from the support module
under the macros module. Some other macro invocations were also using absolute
standard library paths instead of calling into the afore mentioned module
through the special $crate metavariable. This has been changed, thus also
reexporting some other items in support.

Copy link
Copy Markdown
Member

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment thread tokio/src/macros/try_join.rs Outdated
$crate::macros::support::Poll::Pending
} else {
$crate::macros::support::Poll::Ready(Ok(($({
$crate::macros::support::Poll::Ready(::std::result::Result::Ok(($({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you re-export it from $crate::macros::support instead? That's more reliable than using ::std.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, done.

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-macros Module: macros in the main Tokio crate labels Mar 31, 2026
@dybucc dybucc force-pushed the try-join-hygiene branch from c5922db to 2c22fc1 Compare March 31, 2026 10:19
Comment thread tokio/src/macros/try_join.rs Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's fix this one too, while we're at it.

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The improvements in select.rs for 1.50.0 broke the build of Apache DataFusion, but it was very easy to fix - apache/datafusion#21000
I am in favour to improve the last entry in select.rs too!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are more in the other modules:

* https://github.com/dybucc/tokio/blob/2c22fc1973621893f07c43ebb5f49b8e03fabe1e/tokio/src/macros/addr_of.rs#L8

* https://github.com/dybucc/tokio/blob/2c22fc1973621893f07c43ebb5f49b8e03fabe1e/tokio/src/macros/select.rs#L702

* https://github.com/dybucc/tokio/blob/2c22fc1973621893f07c43ebb5f49b8e03fabe1e/tokio/src/macros/support.rs#L16

* https://github.com/dybucc/tokio/blob/2c22fc1973621893f07c43ebb5f49b8e03fabe1e/tokio/src/macros/support.rs#L24

* https://github.com/dybucc/tokio/blob/2c22fc1973621893f07c43ebb5f49b8e03fabe1e/tokio/src/macros/support.rs#L25

* https://github.com/dybucc/tokio/blob/2c22fc1973621893f07c43ebb5f49b8e03fabe1e/tokio/src/macros/trace.rs#L15-L21

I think the one in select.rs is intentionally left because it breaks some axum related crate.

@martin-g Done. Still, is the list item concerning addr_of really meant to use absolute paths? That one is part of a macro matcher and not a macro invocation, so it wouldn't make a lot of sense to force callers to use absolute paths, right?

I'm also not so sure about the support.rs ones, so I've not made changes there either, but I can't make a case against not using absolute paths/$crate-relative paths in this instance.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dybucc You are correct! 👍🏻

Multiple macro expansions were previously assumming the existence of
some standard library symbols to both be in-scope and referring to the
right symbol, and not only having the same identifier.

This has now been refactored into using reexports from the `support`
module under the `macros` module. Some other macro invocations were also
using absolute standard library paths instead of calling into the afore
mentioned module through the special `$crate` macro. This has been
changed, thus also reexporting some other items in `support`.
@dybucc dybucc force-pushed the try-join-hygiene branch from 2c22fc1 to 53277b2 Compare March 31, 2026 14:23
@dybucc dybucc changed the title macros: improve try_join macro hygiene macros: improve overall macro hygiene Mar 31, 2026
Copy link
Copy Markdown
Member

@martin-g martin-g left a comment

Choose a reason for hiding this comment

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

LGTM!

The fixed Pin/Ok/Err may break some users (e.g. hyper - #7929 (comment)) but IMO it is OK.

Copy link
Copy Markdown
Member

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

We have to keep imports to avoid breaking users, but changing the actual uses to full paths sounds good to me.

@Darksonn Darksonn merged commit b4c3246 into tokio-rs:master Apr 2, 2026
89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio Area: The main tokio crate M-macros Module: macros in the main Tokio crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants