Skip to content
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

Cyclic dev-dependencies can cause confusing errors #6765

Open
mikhailOK opened this issue Mar 20, 2019 · 2 comments
Open

Cyclic dev-dependencies can cause confusing errors #6765

mikhailOK opened this issue Mar 20, 2019 · 2 comments
Labels
A-build-execution Area: anything dealing with executing the compiler A-dev-dependencies Area: [dev-dependencies] C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-test S-needs-team-input Status: Needs input from team on whether/how to proceed.

Comments

@mikhailOK
Copy link

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

@mikhailOK mikhailOK added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Mar 20, 2019
@ehuss
Copy link
Contributor

ehuss commented Mar 22, 2019

I think there are some use cases based on other issues (primarily #4242, also #3745, #1686, #432). In my testing, I don't see how people use it (since I get similar errors that you got), but apparently some people use it.

@ehuss ehuss added the A-dev-dependencies Area: [dev-dependencies] label Mar 22, 2019
@Nemo157
Copy link
Member

Nemo157 commented Aug 21, 2019

They work fine in external tests as they are linked against crate1-as-library (so there is no real circular dependency), the problem above is caused because internal tests are using both crate1-as-library via crate2 and crate1-for-tests which are completely separate libraries built from the same source code.

@ehuss ehuss changed the title Disallow cyclic dev-dependencies Cyclic dev-dependencies can cause confusing errors Oct 24, 2019
@epage epage added A-build-execution Area: anything dealing with executing the compiler Command-test S-needs-team-input Status: Needs input from team on whether/how to proceed. labels Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-dev-dependencies Area: [dev-dependencies] C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-test S-needs-team-input Status: Needs input from team on whether/how to proceed.
Projects
Status: No status
Development

No branches or pull requests

4 participants