Skip to content

Commit 26e35d0

Browse files
Macro hygiene of chain!
If someone has a module named `core` and uses `itertools::chain!` then there is a conflict! I improve our macro hygiene test by adding (empty) modules with all the names we might be tempted to use. Without changing `core` in `chain!`, the test failed!
1 parent 4777762 commit 26e35d0

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,16 @@ macro_rules! izip {
393393
/// ```
394394
macro_rules! chain {
395395
() => {
396-
core::iter::empty()
396+
$crate::__std_iter::empty()
397397
};
398398
($first:expr $(, $rest:expr )* $(,)?) => {
399399
{
400-
let iter = core::iter::IntoIterator::into_iter($first);
400+
let iter = $crate::__std_iter::IntoIterator::into_iter($first);
401401
$(
402402
let iter =
403-
core::iter::Iterator::chain(
403+
$crate::__std_iter::Iterator::chain(
404404
iter,
405-
core::iter::IntoIterator::into_iter($rest));
405+
$crate::__std_iter::IntoIterator::into_iter($rest));
406406
)*
407407
iter
408408
}

tests/macros_hygiene.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
mod alloc {}
2+
mod core {}
3+
mod either {}
4+
mod std {}
5+
16
#[test]
27
fn iproduct_hygiene() {
38
let _ = itertools::iproduct!();
@@ -12,3 +17,11 @@ fn izip_hygiene() {
1217
let _ = itertools::izip!(0..6, 0..9);
1318
let _ = itertools::izip!(0..6, 0..9, 0..12);
1419
}
20+
21+
#[test]
22+
fn chain_hygiene() {
23+
let _: ::std::iter::Empty<i32> = itertools::chain!();
24+
let _ = itertools::chain!(0..6);
25+
let _ = itertools::chain!(0..6, 0..9);
26+
let _ = itertools::chain!(0..6, 0..9, 0..12);
27+
}

0 commit comments

Comments
 (0)