Skip to content

Commit 9535dc3

Browse files
committed
Auto merge of #9681 - hi-rustin:rustin-patch-reject, r=ehuss
Warning when using features in replace close #3034 close #2582 r? `@ehuss`
2 parents e6976ec + 771356d commit 9535dc3

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

src/cargo/ops/resolve.rs

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

120130
Some(resolve)

tests/testsuite/replace.rs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,104 @@ 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_stderr(
91+
"\
92+
[UPDATING] [..] index
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+
}
103+
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 [..]
148+
",
149+
)
150+
.run();
151+
}
152+
55153
#[cargo_test]
56154
fn missing_version() {
57155
let p = project()

0 commit comments

Comments
 (0)