Skip to content

Macro cleanups #96

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

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

Conversation

nnethercote
Copy link
Contributor

These make the code easier to read, and the docs much nicer. Details in individual commits.

There are currently two top-level rules: one handling if/else chains
with a final `else`, and one handling if/else chains lacking a final
`else`. But it's possible to handle both cases in a single rule, and
it's shorter and clearer that way.
`@foo` rules are a common Rust macro idiom, but a big downside is they
appear in the docs. This commits puts the `@foo` rules into separate
macros, so they no longer appear in the docs. I also find the macros
easier to read this way.
@nnethercote
Copy link
Contributor Author

Here's what the old docs look like:

macro_rules! cfg_if {
    (
        $(
            if #[cfg( $i_meta:meta )] { $( $i_tokens:tt )* }
        ) else+
        else { $( $e_tokens:tt )* }
    ) => { ... };
    (
        if #[cfg( $i_meta:meta )] { $( $i_tokens:tt )* }
        $(
            else if #[cfg( $e_meta:meta )] { $( $e_tokens:tt )* }
        )*
    ) => { ... };
    (@__items ( $( $_:meta , )* ) ; ) => { ... };
    (
        @__items ( $( $no:meta , )* ) ;
        (( $( $yes:meta )? ) ( $( $tokens:tt )* )) ,
        $( $rest:tt , )*
    ) => { ... };
    (@__identity $( $tokens:tt )* ) => { ... };
}

and the new docs:

macro_rules! cfg_if {
    (
        if #[cfg( $i_meta:meta )] { $( $i_tokens:tt )* }
        $(
            else if #[cfg( $ei_meta:meta )] { $( $ei_tokens:tt )* }
        )*
        $(
            else { $( $e_tokens:tt )* }
        )?
    ) => { ... };
}

Much better!

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.

1 participant