Skip to content

Weird cyclic dependency case #59305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mikhailOK opened this issue Mar 20, 2019 · 1 comment
Closed

Weird cyclic dependency case #59305

mikhailOK opened this issue Mar 20, 2019 · 1 comment

Comments

@mikhailOK
Copy link

Cyclic dependencies through dev-dependencies 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 {}

pub struct ValueReturner {}

impl ValueReturner {
    pub fn return_value(&self) -> Value {
        Value {}
    }
}

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

crate2/src/lib.rs:

use crate1::ValueReturner;

pub fn get_returner() -> ValueReturner {
    ValueReturner {}
}

cargo test -p crate1 fails with a compilation error:

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

Comipler version: rustc 1.35.0-nightly (e68bf8ae1 2019-03-11)

My question is, is there a valid use case for this kind of cyclic dependencies?

@mikhailOK mikhailOK changed the title Weird cycling dependency case Weird cyclic dependency case Mar 20, 2019
@kaichaosun
Copy link

I have the same issue, and asking some help here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants