Skip to content

Commit

Permalink
Warning when using features in replace
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Jul 23, 2021
1 parent add4ffc commit 771356d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
8 changes: 0 additions & 8 deletions src/cargo/core/resolver/dep_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ impl<'a> RegistryQueryer<'a> {
dep.version_req()
);

if dep.features().len() != 0 || !dep.uses_default_features() {
anyhow::bail!(
"patch for `{}` uses the features mechanism. \
default-features and features will not take effect because the patch dependency does not support this mechanism",
dep.package_name()
);
}

let mut summaries = self.registry.query_vec(dep, false)?.into_iter();
let s = summaries.next().ok_or_else(|| {
anyhow::format_err!(
Expand Down
10 changes: 10 additions & 0 deletions src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,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)
Expand Down
59 changes: 54 additions & 5 deletions tests/testsuite/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,64 @@ fn override_with_features() {
.build();

p.cargo("build")
.with_status(101)
.with_stderr(
"\
[UPDATING] [..] index
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])`
[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();
}

Caused by:
patch for `bar` uses the features mechanism. default-features and features \
will not take effect because the patch dependency does not support this mechanism
#[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();
Expand Down

0 comments on commit 771356d

Please sign in to comment.