genemichaels icon indicating copy to clipboard operation
genemichaels copied to clipboard

doesn’t build for me

Open schuelermine opened this issue 2 years ago • 15 comments

I dunno what could be wrong but it just doesn’t build for me. I get the following error:

   Compiling toml v0.5.10
error[E0107]: struct takes 3 generic arguments but 2 generic arguments were supplied
  --> /home/anselmschueler/.cargo/registry/src/index.crates.io-6f17d22bba15001f/toml-0.5.10/src/map.rs:39:22
   |
39 | type MapImpl<K, V> = IndexMap<K, V>;
   |                      ^^^^^^^^ -  - supplied 2 generic arguments
   |                      |
   |                      expected 3 generic arguments
   |
note: struct defined here, with 3 generic parameters: `K`, `V`, `S`
  --> /home/anselmschueler/.cargo/registry/src/index.crates.io-6f17d22bba15001f/indexmap-1.9.2/src/map.rs:76:12
   |
76 | pub struct IndexMap<K, V, S> {
   |            ^^^^^^^^ -  -  -
help: add missing generic argument
   |
39 | type MapImpl<K, V> = IndexMap<K, V, S>;
   |                                   +++

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

schuelermine avatar Apr 02 '23 21:04 schuelermine

Looks like maybe https://github.com/toml-rs/toml/issues/524 ?

andrewbaxter avatar Apr 03 '23 05:04 andrewbaxter

I'm not sure if it's present until indexmap 1.9.2, or if it was a regression in 1.9.2 fixed in 1.9.3 or what. Maybe the autodetection is system dependent too? I can't imagine what would be system dependent though.

Toml is pulled in via cargo-manifest, so I'm not sure I can update it directly. Still investigating...

andrewbaxter avatar Apr 03 '23 05:04 andrewbaxter

Are you running in a container or something? I just tried with the rust container and didn't have any issues, although it used Compiling indexmap v1.9.3 instead of 1.9.1 which toml specifies.

Locally I have

├── cargo-manifest v0.7.1
│   ├── serde v1.0.152
│   │   └── serde_derive v1.0.152 (proc-macro)
│   │       ├── proc-macro2 v1.0.49
│   │       │   └── unicode-ident v1.0.6
│   │       ├── quote v1.0.23
│   │       │   └── proc-macro2 v1.0.49 (*)
│   │       └── syn v1.0.107
│   │           ├── proc-macro2 v1.0.49 (*)
│   │           ├── quote v1.0.23 (*)
│   │           └── unicode-ident v1.0.6
│   └── toml v0.5.10
│       ├── indexmap v1.9.2
│       │   └── hashbrown v0.12.3
│       │   [build-dependencies]
│       │   └── autocfg v1.1.0
│       └── serde v1.0.152 (*)

(1.9.2)

andrewbaxter avatar Apr 03 '23 10:04 andrewbaxter

It said indexmap v1.9.3 for me too. I’m compiling on bare hardware, running NixOS unstable with Rust unstable from the Fenix overlay. Let me try switching to stable Rust.

schuelermine avatar Apr 03 '23 10:04 schuelermine

Interesting. It only fails to compile if I use my package manager’s version of Rust.

schuelermine avatar Apr 03 '23 11:04 schuelermine

I'm still trying to figure out what's going on here. AFAICT in https://github.com/bluss/indexmap/commit/99848fff179911f2573011dfc2859c182c9c0cfb indexmap stopped using autocfg for detecting std presence, and instead std is on by default. That's from before 1.9.1 and default is on in my builds.

autocfg runs rustc in weird ways to determine system capabilities. It wouldn't surprise me if that didn't behave as expected on NixOS... but it doesn't look like that's being used.

But if it's not used, what else could be causing nondeterminism here?

andrewbaxter avatar Apr 03 '23 11:04 andrewbaxter

Hmm, I do see autocfg showing up in the build

   Compiling autocfg v1.1.0

andrewbaxter avatar Apr 03 '23 11:04 andrewbaxter

https://github.com/bluss/indexmap/blob/master/Cargo.toml doesn't include autocfg anywhere I can tell, but

$ cargo tree -i autocfg
autocfg v1.1.0
[build-dependencies]
└── indexmap v1.9.2
    └── toml v0.5.10
        └── cargo-manifest v0.7.1
            └── genemichaels v0.1.21

and it shows up in https://crates.io/crates/indexmap/1.9.3/dependencies

andrewbaxter avatar Apr 03 '23 11:04 andrewbaxter

I forked cargo-manifest to bump toml which should set the indexmap flag... I think. Does adding

[patch.crates-io]
cargo-manifest = { git = "https://github.com/andrewbaxter/fork-cargo-manifest", rev = "1957fc45baa9b16f894ffcbaecbd8289a026d2a9" }

to the Cargo.toml file help? I can push a branch, but I'm not sure if that would make things easier.

That said, it looks like toml_edit includes the indexmap std feature but toml doesn't, I'm not sure if that was intentional.

andrewbaxter avatar Apr 03 '23 11:04 andrewbaxter

Here's my best guess as to what's happening, and I think updating the toml dep should fix it: https://github.com/toml-rs/toml/issues/539#issuecomment-1494339641

If that works for you, I'll make an MR for cargo-manifest.

andrewbaxter avatar Apr 03 '23 13:04 andrewbaxter

Yep, your patch fixes it.

schuelermine avatar Apr 03 '23 17:04 schuelermine

Still perplexed by why it works with the rustup Rust but not the system Rust…

schuelermine avatar Apr 03 '23 17:04 schuelermine

Oh excellent!

Yeah, I can't help there I think, but my best guess is it's how autocfg checks for std library presence, maybe to do with how files are stored in NixOS... it might be worth pursuing in that repo.

In any case though, with the fix I think it doesn't rely on autocfg at all (hopefully). I'll open the PR upstream for it.

andrewbaxter avatar Apr 03 '23 18:04 andrewbaxter

The problem appears to also be fixed by https://github.com/nix-community/fenix/pull/100

schuelermine avatar Apr 04 '23 09:04 schuelermine

Oh awesome! Okay, well in any case it would be good to get it fixed here too just in case someone else has the issue, and doesn't hurt to bump the dep versions.

andrewbaxter avatar Apr 04 '23 14:04 andrewbaxter

FWIW upstream was fixed, I think I've updated cargo-manifest now so I believe this has been resolved for a while.

andrewbaxter avatar Jul 07 '24 06:07 andrewbaxter