Skip to content

Commit add4ffc

Browse files
committed
Reject when using features in replace
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
1 parent 18f2598 commit add4ffc

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/cargo/core/resolver/dep_cache.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ impl<'a> RegistryQueryer<'a> {
105105
dep.version_req()
106106
);
107107

108+
if dep.features().len() != 0 || !dep.uses_default_features() {
109+
anyhow::bail!(
110+
"patch for `{}` uses the features mechanism. \
111+
default-features and features will not take effect because the patch dependency does not support this mechanism",
112+
dep.package_name()
113+
);
114+
}
115+
108116
let mut summaries = self.registry.query_vec(dep, false)?.into_iter();
109117
let s = summaries.next().ok_or_else(|| {
110118
anyhow::format_err!(

tests/testsuite/replace.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,55 @@ fn override_simple() {
5252
.run();
5353
}
5454

55+
#[cargo_test]
56+
fn override_with_features() {
57+
Package::new("bar", "0.1.0").publish();
58+
59+
let bar = git::repo(&paths::root().join("override"))
60+
.file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
61+
.file("src/lib.rs", "pub fn bar() {}")
62+
.build();
63+
64+
let p = project()
65+
.file(
66+
"Cargo.toml",
67+
&format!(
68+
r#"
69+
[package]
70+
name = "foo"
71+
version = "0.0.1"
72+
authors = []
73+
74+
[dependencies]
75+
bar = "0.1.0"
76+
77+
[replace]
78+
"bar:0.1.0" = {{ git = '{}', features = ["some_feature"] }}
79+
"#,
80+
bar.url()
81+
),
82+
)
83+
.file(
84+
"src/lib.rs",
85+
"extern crate bar; pub fn foo() { bar::bar(); }",
86+
)
87+
.build();
88+
89+
p.cargo("build")
90+
.with_status(101)
91+
.with_stderr(
92+
"\
93+
[UPDATING] [..] index
94+
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])`
95+
96+
Caused by:
97+
patch for `bar` uses the features mechanism. default-features and features \
98+
will not take effect because the patch dependency does not support this mechanism
99+
",
100+
)
101+
.run();
102+
}
103+
55104
#[cargo_test]
56105
fn missing_version() {
57106
let p = project()

0 commit comments

Comments
 (0)