rust-lang / rust-lang/cargo

Cyclic dev-dependencies can cause confusing errors

Open
#6,765 4 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-build-execution A-dev-dependencies C-feature-request Command-test S-propose-close
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

Describe the problem you are trying to solve
Cargo detects cyclic dependencies, but allows crates to depends on each other in [dev-dependencies]. This can lead to a confusing error message

Here is a minimal repro: https://github.com/mikhailOK/bad-cargo-cyclic-dependency

Two crates, crate1 and crate2
crate2 depends on crate1, but crate1 has crate2 in [dev-dependencies]

crate1/src/lib.rs:

#[derive(PartialEq, Eq, Debug)]
pub struct Value {}

#[cfg(test)]
mod tests {
    #[test]
    pub fn mismatched_types() {
        assert_eq!(crate2::return_value(), crate::Value {});
    }
}

crate2/src/lib.rs:

pub fn return_value() -> crate1::Value {
    crate1::Value {}
}

cargo test -p crate1 fails with a compilation error:

error[E0308]: mismatched types
 --> crate1/src/lib.rs:8:9
  |
8 |         assert_eq!(crate2::return_value(), crate::Value {});
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `crate1::Value`, found struct `Value`
  |
  = note: expected type `crate1::Value`
             found type `Value`

Describe the solution you'd like
My question is, is there a valid use case for this kind of cyclic dependencies?
If there isn't, can this case be a cargo error?

Notes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the linked minimal reproduction and the shown cargo test -p crate1 command to confirm the confusing type error. Then inspect Cargo's existing cyclic-dependency handling and determine whether cycles involving [dev-dependencies] have valid use cases; done means reaching a project decision and defining the expected Cargo error behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.