indexmap-rs/indexmap

Compilation bug

Closed this issue · 1 comments

All versions 1.2.0-1.9.3 has same compilation error
Vesion indexmap 1.0.0-1.2.0 complies Ok
The error from 1.9.3:

error[E0107]: struct takes 3 generic arguments but 2 generic arguments were supplied
  --> /home/builder/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-0.4.13/src/ready_cache/cache.rs:65:25
   |
65 |     pending_cancel_txs: IndexMap<K, CancelTx>,
   |                         ^^^^^^^^ -  -------- supplied 2 generic arguments
   |                         |
   |                         expected 3 generic arguments
   |
note: struct defined here, with 3 generic parameters: `K`, `V`, `S`
  --> /home/builder/.cargo/registry/src/index.crates.io-6f17d22bba15001f/indexmap-1.9.3/src/map.rs:76:12
   |
76 | pub struct IndexMap<K, V, S> {
   |            ^^^^^^^^ -  -  -
help: add missing generic argument
   |
65 |     pending_cancel_txs: IndexMap<K, CancelTx, S>,
   |                                             +++

error[E0107]: struct takes 3 generic arguments but 2 generic arguments were supplied
  --> /home/builder/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-0.4.13/src/ready_cache/cache.rs:73:12
   |
73 |     ready: IndexMap<K, (S, CancelPair)>,
   |            ^^^^^^^^ -  --------------- supplied 2 generic arguments
   |            |
   |            expected 3 generic arguments
   |
note: struct defined here, with 3 generic parameters: `K`, `V`, `S`
  --> /home/builder/.cargo/registry/src/index.crates.io-6f17d22bba15001f/indexmap-1.9.3/src/map.rs:76:12
   |
76 | pub struct IndexMap<K, V, S> {
   |            ^^^^^^^^ -  -  -
help: add missing generic argument
   |
73 |     ready: IndexMap<K, (S, CancelPair), S>,
   |                                       +++

For more information about this error, try `rustc --explain E0107`.
error: could not compile `tower` (lib) due to 2 previous errors

IndexMap does have three generic parameters, but it provides a default S hasher when the "std" feature is enabled. The problem you're running into is in the way we added no-std with backward compatibility from before there was any "std" feature defined, so we wouldn't break anyone that wasn't explicitly enabling it (especially with default-features = false). So we added build-script to detect the presence of std for the target and automatically use it. The problem is that some environments fail that detection, for reasons we never figured out, and then code which assumed the std-enabled API (like tower is here) would fail to compile.

The explicit "std" feature was added in indexmap v1.5.2. You could ask tower to upgrade their dependency to that point with features = ["std"] enabled, or you can add that as your own dependency and Cargo will unify the feature set.

In indexmap v2, we solved this by removing that autodetection, since we don't need backwards compatibility in a semver change. So there's always an explicit "std" feature, which is also enabled in the default feature set. I also opened tower-rs/tower#741 to offer that upgrade.