Skip to content

Commit 771356d

Browse files
committed
Warning when using features in replace
Signed-off-by: hi-rustin <[email protected]>
1 parent add4ffc commit 771356d

File tree

3 files changed

+64
-13
lines changed

3 files changed

+64
-13
lines changed

src/cargo/core/resolver/dep_cache.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,6 @@ 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-
116108
let mut summaries = self.registry.query_vec(dep, false)?.into_iter();
117109
let s = summaries.next().ok_or_else(|| {
118110
anyhow::format_err!(

src/cargo/ops/resolve.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ pub fn resolve_ws_with_opts<'cfg>(
113113
.shell()
114114
.warn(format!("package replacement is not used: {}", replace_spec))?
115115
}
116+
117+
if dep.features().len() != 0 || !dep.uses_default_features() {
118+
ws.config()
119+
.shell()
120+
.warn(format!(
121+
"replacement for `{}` uses the features mechanism. \
122+
default-features and features will not take effect because the replacement dependency does not support this mechanism",
123+
dep.package_name()
124+
))?
125+
}
116126
}
117127

118128
Some(resolve)

tests/testsuite/replace.rs

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,64 @@ fn override_with_features() {
8787
.build();
8888

8989
p.cargo("build")
90-
.with_status(101)
9190
.with_stderr(
9291
"\
9392
[UPDATING] [..] index
94-
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])`
93+
[UPDATING] git repository `[..]`
94+
[WARNING] replacement for `bar` uses the features mechanism. default-features and features \
95+
will not take effect because the replacement dependency does not support this mechanism
96+
[COMPILING] bar v0.1.0 (file://[..])
97+
[COMPILING] foo v0.0.1 ([CWD])
98+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
99+
",
100+
)
101+
.run();
102+
}
95103

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
104+
#[cargo_test]
105+
fn override_with_setting_default_features() {
106+
Package::new("bar", "0.1.0").publish();
107+
108+
let bar = git::repo(&paths::root().join("override"))
109+
.file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
110+
.file("src/lib.rs", "pub fn bar() {}")
111+
.build();
112+
113+
let p = project()
114+
.file(
115+
"Cargo.toml",
116+
&format!(
117+
r#"
118+
[package]
119+
name = "foo"
120+
version = "0.0.1"
121+
authors = []
122+
123+
[dependencies]
124+
bar = "0.1.0"
125+
126+
[replace]
127+
"bar:0.1.0" = {{ git = '{}', default-features = false, features = ["none_default_feature"] }}
128+
"#,
129+
bar.url()
130+
),
131+
)
132+
.file(
133+
"src/lib.rs",
134+
"extern crate bar; pub fn foo() { bar::bar(); }",
135+
)
136+
.build();
137+
138+
p.cargo("build")
139+
.with_stderr(
140+
"\
141+
[UPDATING] [..] index
142+
[UPDATING] git repository `[..]`
143+
[WARNING] replacement for `bar` uses the features mechanism. default-features and features \
144+
will not take effect because the replacement dependency does not support this mechanism
145+
[COMPILING] bar v0.1.0 (file://[..])
146+
[COMPILING] foo v0.0.1 ([CWD])
147+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
99148
",
100149
)
101150
.run();

0 commit comments

Comments
 (0)