Search code examples
rustrust-cargoserderust-criterion

Compile error when running cargo bench (criterion/serde)


I added following lines to the cargo.toml of my project in order to benchmark my code:

[dev-dependencies]
criterion = "0.3"

[[bench]]
name = "samples"
harness = false

After running cargo bench, I get a lot of errors similar to the following:

Compiling criterion v0.3.4
error[E0603]: module `export` is private
   --> C:\Development\Rust\cargo\registry\src\github.com-1ecc6299db9ec823\criterion-0.3.4\src\connection.rs:201:17
    |
201 | #[derive(Debug, Deserialize)]
    |                 ^^^^^^^^^^^ private module
    |
note: the module `export` is defined here
   --> C:\Development\Rust\cargo\registry\src\github.com-1ecc6299db9ec823\serde-1.0.123\src\lib.rs:275:5
    |
275 | use self::__private as export;

The error message looks to me that there is a problem between serde and criterion. But I did not find this error message in either project issues, so there may be a hidden reason in my workspace.

Some additional information:

  • the project is compiled using the nightly toolchain
  • there is just one explicit dependency (proc macros) in the cargo.toml which transitively references syn, quote and proc-macro2

Solution

  • The serde version and serde_derive version in your dependency graph are mismatched. You need to use cargo update to bring them in sync. The two must have the identical version number always.