diff --git a/src/cargo/ops/resolve.rs b/src/cargo/ops/resolve.rs index 6435ef6b127..c305bc3a353 100644 --- a/src/cargo/ops/resolve.rs +++ b/src/cargo/ops/resolve.rs @@ -115,6 +115,16 @@ pub fn resolve_ws_with_opts<'cfg>( .shell() .warn(format!("package replacement is not used: {}", replace_spec))? } + + if dep.features().len() != 0 || !dep.uses_default_features() { + ws.config() + .shell() + .warn(format!( + "replacement for `{}` uses the features mechanism. \ + default-features and features will not take effect because the replacement dependency does not support this mechanism", + dep.package_name() + ))? + } } Some(resolve) diff --git a/tests/testsuite/replace.rs b/tests/testsuite/replace.rs index 864bb83be1b..363e6c54b3b 100644 --- a/tests/testsuite/replace.rs +++ b/tests/testsuite/replace.rs @@ -52,6 +52,104 @@ fn override_simple() { .run(); } +#[cargo_test] +fn override_with_features() { + Package::new("bar", "0.1.0").publish(); + + let bar = git::repo(&paths::root().join("override")) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("src/lib.rs", "pub fn bar() {}") + .build(); + + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + bar = "0.1.0" + + [replace] + "bar:0.1.0" = {{ git = '{}', features = ["some_feature"] }} + "#, + bar.url() + ), + ) + .file( + "src/lib.rs", + "extern crate bar; pub fn foo() { bar::bar(); }", + ) + .build(); + + p.cargo("build") + .with_stderr( + "\ +[UPDATING] [..] index +[UPDATING] git repository `[..]` +[WARNING] replacement for `bar` uses the features mechanism. default-features and features \ +will not take effect because the replacement dependency does not support this mechanism +[COMPILING] bar v0.1.0 (file://[..]) +[COMPILING] foo v0.0.1 ([CWD]) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} + +#[cargo_test] +fn override_with_setting_default_features() { + Package::new("bar", "0.1.0").publish(); + + let bar = git::repo(&paths::root().join("override")) + .file("Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("src/lib.rs", "pub fn bar() {}") + .build(); + + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + bar = "0.1.0" + + [replace] + "bar:0.1.0" = {{ git = '{}', default-features = false, features = ["none_default_feature"] }} + "#, + bar.url() + ), + ) + .file( + "src/lib.rs", + "extern crate bar; pub fn foo() { bar::bar(); }", + ) + .build(); + + p.cargo("build") + .with_stderr( + "\ +[UPDATING] [..] index +[UPDATING] git repository `[..]` +[WARNING] replacement for `bar` uses the features mechanism. default-features and features \ +will not take effect because the replacement dependency does not support this mechanism +[COMPILING] bar v0.1.0 (file://[..]) +[COMPILING] foo v0.0.1 ([CWD]) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} + #[cargo_test] fn missing_version() { let p = project()