Peternator7 / strum

A small rust library for adding custom derives to enums
https://crates.io/crates/strum
MIT License
1.8k stars 152 forks source link

Itertools 0.13.0 and strum derive macro EnumIter break if both are used at the same time #358

Closed VorpalBlade closed 6 months ago

VorpalBlade commented 6 months ago
// Uncomment this line and this fails to build (with itertools 0.13.0, works with 0.12.1)
// use itertools::Itertools;

#[derive(Debug, strum::EnumIter)]
enum A {
    B,
    C,
}

This leads to the very strange following error if the mentioned line is uncommented:

   Compiling itertools_strum v0.1.0 (/home/arvid/src/itertools_strum)
error[E0277]: the trait bound `usize: IteratorIndex<&mut AIter>` is not satisfied
   --> src/main.rs:4:17
    |
4   | #[derive(Debug, strum::EnumIter)]
    |                 ^^^^^^^^^^^^^^^ the trait `IteratorIndex<&mut AIter>` is not implemented for `usize`
    |
    = help: the following other types implement trait `IteratorIndex<I>`:
              RangeFull
              std::ops::Range<usize>
              RangeFrom<usize>
              RangeTo<usize>
              RangeInclusive<usize>
              RangeToInclusive<usize>
note: required by a bound in `itertools::Itertools::get`
   --> /home/arvid/.cargo/registry/src/index.crates.io-6f17d22bba15001f/itertools-0.13.0/src/lib.rs:554:12
    |
551 |     fn get<R>(self, index: R) -> R::Output
    |        --- required by a bound in this associated function
...
554 |         R: traits::IteratorIndex<Self>,
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Itertools::get`
    = note: this error originates in the derive macro `strum::EnumIter` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `itertools_strum` (bin "itertools_strum") due to 2 previous errors

I have no idea if this is a strum or itertools bug. As such I have reported this to both, see https://github.com/rust-itertools/itertools/issues/942

Using rustc 1.78.0 (9b00956e5 2024-04-29).

[dependencies]
itertools = "0.13.0"
strum = { version = "0.26.2", features = ["derive"] }
VorpalBlade commented 6 months ago

Apparently it is a macro hygiene issue on strum's side, where it should call get fully qualified instead.

bluurryy commented 6 months ago

PR #357 fixes this.