Skip to content

Commit 5ad3e1a

Browse files
bors[bot]SkiFire13
andauthored
Merge #507
507: Make macros more hygienic and callable without importing them r=jswrenn a=SkiFire13 Fixes #506 Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com>
2 parents 00756e0 + 79e39cb commit 5ad3e1a

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,16 @@ macro_rules! iproduct {
253253
$I
254254
);
255255
(@flatten $I:expr, $J:expr, $($K:expr,)*) => (
256-
iproduct!(@flatten $crate::cons_tuples(iproduct!($I, $J)), $($K,)*)
256+
$crate::iproduct!(@flatten $crate::cons_tuples($crate::iproduct!($I, $J)), $($K,)*)
257257
);
258258
($I:expr) => (
259259
$crate::__std_iter::IntoIterator::into_iter($I)
260260
);
261261
($I:expr, $J:expr) => (
262-
$crate::Itertools::cartesian_product(iproduct!($I), iproduct!($J))
262+
$crate::Itertools::cartesian_product($crate::iproduct!($I), $crate::iproduct!($J))
263263
);
264264
($I:expr, $J:expr, $($K:expr),+) => (
265-
iproduct!(@flatten iproduct!($I, $J), $($K,)+)
265+
$crate::iproduct!(@flatten $crate::iproduct!($I, $J), $($K,)+)
266266
);
267267
}
268268

@@ -313,7 +313,7 @@ macro_rules! izip {
313313

314314
// The "b" identifier is a different identifier on each recursion level thanks to hygiene.
315315
( @closure $p:pat => ( $($tup:tt)* ) , $_iter:expr $( , $tail:expr )* ) => {
316-
izip!(@closure ($p, b) => ( $($tup)*, b ) $( , $tail )*)
316+
$crate::izip!(@closure ($p, b) => ( $($tup)*, b ) $( , $tail )*)
317317
};
318318

319319
// unary
@@ -323,18 +323,18 @@ macro_rules! izip {
323323

324324
// binary
325325
($first:expr, $second:expr $(,)*) => {
326-
izip!($first)
326+
$crate::izip!($first)
327327
.zip($second)
328328
};
329329

330330
// n-ary where n > 2
331331
( $first:expr $( , $rest:expr )* $(,)* ) => {
332-
izip!($first)
332+
$crate::izip!($first)
333333
$(
334334
.zip($rest)
335335
)*
336336
.map(
337-
izip!(@closure a => (a) $( , $rest )*)
337+
$crate::izip!(@closure a => (a) $( , $rest )*)
338338
)
339339
};
340340
}

tests/macros_hygiene.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[test]
2+
fn iproduct_hygiene() {
3+
let _ = itertools::iproduct!(0..6);
4+
let _ = itertools::iproduct!(0..6, 0..9);
5+
let _ = itertools::iproduct!(0..6, 0..9, 0..12);
6+
}
7+
8+
#[test]
9+
fn izip_hygiene() {
10+
let _ = itertools::izip!(0..6);
11+
let _ = itertools::izip!(0..6, 0..9);
12+
let _ = itertools::izip!(0..6, 0..9, 0..12);
13+
}

0 commit comments

Comments
 (0)