Skip to content

Commit 26b925c

Browse files
committed
Use $crate in recursive macro calls
This makes it possible to use `ndarray::s![]` and `ndarray::azip!()` without importing them with `macro_use` or `use`.
1 parent 44c7fbe commit 26b925c

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/slice.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ macro_rules! s(
553553
#[allow(unsafe_code)]
554554
unsafe {
555555
$crate::SliceInfo::new_unchecked(
556-
[$($stack)* s!(@convert r, $s)],
556+
[$($stack)* $crate::s!(@convert r, $s)],
557557
out_dim,
558558
)
559559
}
@@ -568,7 +568,7 @@ macro_rules! s(
568568
#[allow(unsafe_code)]
569569
unsafe {
570570
$crate::SliceInfo::new_unchecked(
571-
[$($stack)* s!(@convert r)],
571+
[$($stack)* $crate::s!(@convert r)],
572572
out_dim,
573573
)
574574
}
@@ -577,19 +577,19 @@ macro_rules! s(
577577
};
578578
// convert a..b;c into @convert(a..b, c), final item, trailing comma
579579
(@parse $dim:expr, [$($stack:tt)*] $r:expr;$s:expr ,) => {
580-
s![@parse $dim, [$($stack)*] $r;$s]
580+
$crate::s![@parse $dim, [$($stack)*] $r;$s]
581581
};
582582
// convert a..b into @convert(a..b), final item, trailing comma
583583
(@parse $dim:expr, [$($stack:tt)*] $r:expr ,) => {
584-
s![@parse $dim, [$($stack)*] $r]
584+
$crate::s![@parse $dim, [$($stack)*] $r]
585585
};
586586
// convert a..b;c into @convert(a..b, c)
587587
(@parse $dim:expr, [$($stack:tt)*] $r:expr;$s:expr, $($t:tt)*) => {
588588
match $r {
589589
r => {
590-
s![@parse
590+
$crate::s![@parse
591591
$crate::SliceNextDim::next_dim(&r, $dim),
592-
[$($stack)* s!(@convert r, $s),]
592+
[$($stack)* $crate::s!(@convert r, $s),]
593593
$($t)*
594594
]
595595
}
@@ -599,9 +599,9 @@ macro_rules! s(
599599
(@parse $dim:expr, [$($stack:tt)*] $r:expr, $($t:tt)*) => {
600600
match $r {
601601
r => {
602-
s![@parse
602+
$crate::s![@parse
603603
$crate::SliceNextDim::next_dim(&r, $dim),
604-
[$($stack)* s!(@convert r),]
604+
[$($stack)* $crate::s!(@convert r),]
605605
$($t)*
606606
]
607607
}
@@ -618,6 +618,6 @@ macro_rules! s(
618618
($($t:tt)*) => {
619619
// The extra `*&` is a workaround for this compiler bug:
620620
// https://github.com/rust-lang/rust/issues/23014
621-
&*&s![@parse ::std::marker::PhantomData::<$crate::Ix0>, [] $($t)*]
621+
&*&$crate::s![@parse ::std::marker::PhantomData::<$crate::Ix0>, [] $($t)*]
622622
};
623623
);

src/zip/zipmacro.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@
8585
macro_rules! azip {
8686
// Build Zip Rule (index)
8787
(@parse [index => $a:expr, $($aa:expr,)*] $t1:tt in $t2:tt) => {
88-
azip!(@finish ($crate::Zip::indexed($a)) [$($aa,)*] $t1 in $t2)
88+
$crate::azip!(@finish ($crate::Zip::indexed($a)) [$($aa,)*] $t1 in $t2)
8989
};
9090
// Build Zip Rule (no index)
9191
(@parse [$a:expr, $($aa:expr,)*] $t1:tt in $t2:tt) => {
92-
azip!(@finish ($crate::Zip::from($a)) [$($aa,)*] $t1 in $t2)
92+
$crate::azip!(@finish ($crate::Zip::from($a)) [$($aa,)*] $t1 in $t2)
9393
};
9494
// Build Finish Rule (both)
9595
(@finish ($z:expr) [$($aa:expr,)*] [$($p:pat,)+] in { $($t:tt)*}) => {
@@ -105,32 +105,32 @@ macro_rules! azip {
105105
// parsing stack: [expressions] [patterns] (one per operand)
106106
// index uses empty [] -- must be first
107107
(@parse [] [] index $i:pat, $($t:tt)*) => {
108-
azip!(@parse [index =>] [$i,] $($t)*);
108+
$crate::azip!(@parse [index =>] [$i,] $($t)*);
109109
};
110110
(@parse [$($exprs:tt)*] [$($pats:tt)*] mut $x:ident ($e:expr) $($t:tt)*) => {
111-
azip!(@parse [$($exprs)* $e,] [$($pats)* mut $x,] $($t)*);
111+
$crate::azip!(@parse [$($exprs)* $e,] [$($pats)* mut $x,] $($t)*);
112112
};
113113
(@parse [$($exprs:tt)*] [$($pats:tt)*] mut $x:ident $($t:tt)*) => {
114-
azip!(@parse [$($exprs)* &mut $x,] [$($pats)* mut $x,] $($t)*);
114+
$crate::azip!(@parse [$($exprs)* &mut $x,] [$($pats)* mut $x,] $($t)*);
115115
};
116116
(@parse [$($exprs:tt)*] [$($pats:tt)*] , $($t:tt)*) => {
117-
azip!(@parse [$($exprs)*] [$($pats)*] $($t)*);
117+
$crate::azip!(@parse [$($exprs)*] [$($pats)*] $($t)*);
118118
};
119119
(@parse [$($exprs:tt)*] [$($pats:tt)*] ref $x:ident ($e:expr) $($t:tt)*) => {
120-
azip!(@parse [$($exprs)* $e,] [$($pats)* $x,] $($t)*);
120+
$crate::azip!(@parse [$($exprs)* $e,] [$($pats)* $x,] $($t)*);
121121
};
122122
(@parse [$($exprs:tt)*] [$($pats:tt)*] ref $x:ident $($t:tt)*) => {
123-
azip!(@parse [$($exprs)* &$x,] [$($pats)* $x,] $($t)*);
123+
$crate::azip!(@parse [$($exprs)* &$x,] [$($pats)* $x,] $($t)*);
124124
};
125125
(@parse [$($exprs:tt)*] [$($pats:tt)*] $x:ident ($e:expr) $($t:tt)*) => {
126-
azip!(@parse [$($exprs)* $e,] [$($pats)* &$x,] $($t)*);
126+
$crate::azip!(@parse [$($exprs)* $e,] [$($pats)* &$x,] $($t)*);
127127
};
128128
(@parse [$($exprs:tt)*] [$($pats:tt)*] $x:ident $($t:tt)*) => {
129-
azip!(@parse [$($exprs)* &$x,] [$($pats)* &$x,] $($t)*);
129+
$crate::azip!(@parse [$($exprs)* &$x,] [$($pats)* &$x,] $($t)*);
130130
};
131131
(@parse [$($exprs:tt)*] [$($pats:tt)*] $($t:tt)*) => { };
132132
($($t:tt)*) => {
133-
azip!(@parse [] [] $($t)*);
133+
$crate::azip!(@parse [] [] $($t)*);
134134
}
135135
}
136136

0 commit comments

Comments
 (0)