Skip to content

Commit 8ef8e9f

Browse files
nnethercotetgross35
authored andcommitted
Have a single top-level rule.
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.
1 parent 2400b38 commit 8ef8e9f

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

src/lib.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,24 @@
3333
/// information.
3434
#[macro_export]
3535
macro_rules! cfg_if {
36-
// match if/else chains with a final `else`
37-
(
38-
$(
39-
if #[cfg( $i_meta:meta )] { $( $i_tokens:tt )* }
40-
) else+
41-
else { $( $e_tokens:tt )* }
42-
) => {
43-
$crate::cfg_if! {
44-
@__items () ;
45-
$(
46-
(( $i_meta ) ( $( $i_tokens )* )) ,
47-
)+
48-
(() ( $( $e_tokens )* )) ,
49-
}
50-
};
51-
52-
// match if/else chains lacking a final `else`
5336
(
5437
if #[cfg( $i_meta:meta )] { $( $i_tokens:tt )* }
5538
$(
56-
else if #[cfg( $e_meta:meta )] { $( $e_tokens:tt )* }
39+
else if #[cfg( $ei_meta:meta )] { $( $ei_tokens:tt )* }
5740
)*
41+
$(
42+
else { $( $e_tokens:tt )* }
43+
)?
5844
) => {
5945
$crate::cfg_if! {
6046
@__items () ;
61-
(( $i_meta ) ( $( $i_tokens )* )) ,
47+
(( $i_meta ) ( $( $i_tokens )* )),
6248
$(
63-
(( $e_meta ) ( $( $e_tokens )* )) ,
49+
(( $ei_meta ) ( $( $ei_tokens )* )),
6450
)*
51+
$(
52+
(() ( $( $e_tokens )* )),
53+
)?
6554
}
6655
};
6756

@@ -72,7 +61,7 @@ macro_rules! cfg_if {
7261
(@__items ( $( $_:meta , )* ) ; ) => {};
7362
(
7463
@__items ( $( $no:meta , )* ) ;
75-
(( $( $yes:meta )? ) ( $( $tokens:tt )* )) ,
64+
(( $( $yes:meta )? ) ( $( $tokens:tt )* )),
7665
$( $rest:tt , )*
7766
) => {
7867
// Emit all items within one block, applying an appropriate #[cfg]. The

0 commit comments

Comments
 (0)