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

dev-dependencies.crate features leaked into dependencies.crate features #31807

Closed
lipanski opened this issue Feb 21, 2016 · 1 comment
Closed

Comments

@lipanski
Copy link

I have a crate (let's call it greet) with a feature hello that is not enabled by default. I want to use this feature in my other crate (let's call it bug), but only when running tests. According to the cargo documentation this should be possible by using dev-dependencies.

However, I've noticed that features I enable in the dev-dependencies.greet block are also used when building my binary (e.g. cargo run or cargo build).

I'm using Rust 1.6.0 (but this was also happening in 1.5.0).


The greet crate:

# Cargo.toml

[package]
name = "greet"
version = "0.1.0"

[features]
default = []
hello = []

# src/lib.rs

#[cfg(feature = "hello")]
pub fn greeting() -> &'static str {
    "hello"
}

#[cfg(not(feature = "hello"))]
pub fn greeting() -> &'static str {
    "undefined"
}

The bug crate, using this previous crate greet:

# Cargo.toml

[package]
name = "bug"
version = "0.1.0"

[dependencies.greet]
path = "../greet"
features = []

[dev-dependencies.greet]
path = "../greet"
features = ["hello"]

# src/main.rs

extern crate greet;

fn main() {
    assert_eq!("undefined", greet::greeting());
}

#[cfg(test)]
mod tests {
    extern crate greet;

    #[test]
    fn assert_greeting() {
        assert_eq!("hello", greet::greeting());
    }
}

The assert on cargo test passes, the one on cargo run fails - even though I'm not enabling the hello feature in my dependencies.greet block.

I'd expect both assertions to pass.

@lipanski
Copy link
Author

not sure if I should rather report it to cargo?!

indeed, it seems to be a duplicate of rust-lang/cargo#1796

so I guess we can close this one.

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

1 participant