Skip to content

Commit 18f2598

Browse files
committed
Auto merge of #9666 - hi-rustin:rustin-patch-warn, r=ehuss
Warning when using features in patch part of #3034
2 parents cc80b40 + a846226 commit 18f2598

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

src/cargo/core/registry.rs

+8
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@ impl<'cfg> PackageRegistry<'cfg> {
292292
dep.package_name()
293293
);
294294

295+
if dep.features().len() != 0 || !dep.uses_default_features() {
296+
self.source_config.config().shell().warn(format!(
297+
"patch for `{}` uses the features mechanism. \
298+
default-features and features will not take effect because the patch dependency does not support this mechanism",
299+
dep.package_name()
300+
))?;
301+
}
302+
295303
// Go straight to the source for resolving `dep`. Load it as we
296304
// normally would and then ask it directly for the list of summaries
297305
// corresponding to this `dep`.

tests/testsuite/patch.rs

+96
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,102 @@ fn add_ignored_patch() {
787787
.run();
788788
}
789789

790+
#[cargo_test]
791+
fn add_patch_with_features() {
792+
Package::new("bar", "0.1.0").publish();
793+
794+
let p = project()
795+
.file(
796+
"Cargo.toml",
797+
r#"
798+
[package]
799+
name = "foo"
800+
version = "0.0.1"
801+
authors = []
802+
803+
[dependencies]
804+
bar = "0.1.0"
805+
806+
[patch.crates-io]
807+
bar = { path = 'bar', features = ["some_feature"] }
808+
"#,
809+
)
810+
.file("src/lib.rs", "")
811+
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
812+
.file("bar/src/lib.rs", r#""#)
813+
.build();
814+
815+
p.cargo("build")
816+
.with_stderr(
817+
"\
818+
[WARNING] patch for `bar` uses the features mechanism. \
819+
default-features and features will not take effect because the patch dependency does not support this mechanism
820+
[UPDATING] `[ROOT][..]` index
821+
[COMPILING] bar v0.1.0 ([CWD]/bar)
822+
[COMPILING] foo v0.0.1 ([CWD])
823+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
824+
",
825+
)
826+
.run();
827+
p.cargo("build")
828+
.with_stderr(
829+
"\
830+
[WARNING] patch for `bar` uses the features mechanism. \
831+
default-features and features will not take effect because the patch dependency does not support this mechanism
832+
[FINISHED] [..]
833+
",
834+
)
835+
.run();
836+
}
837+
838+
#[cargo_test]
839+
fn add_patch_with_setting_default_features() {
840+
Package::new("bar", "0.1.0").publish();
841+
842+
let p = project()
843+
.file(
844+
"Cargo.toml",
845+
r#"
846+
[package]
847+
name = "foo"
848+
version = "0.0.1"
849+
authors = []
850+
851+
[dependencies]
852+
bar = "0.1.0"
853+
854+
[patch.crates-io]
855+
bar = { path = 'bar', default-features = false, features = ["none_default_feature"] }
856+
"#,
857+
)
858+
.file("src/lib.rs", "")
859+
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
860+
.file("bar/src/lib.rs", r#""#)
861+
.build();
862+
863+
p.cargo("build")
864+
.with_stderr(
865+
"\
866+
[WARNING] patch for `bar` uses the features mechanism. \
867+
default-features and features will not take effect because the patch dependency does not support this mechanism
868+
[UPDATING] `[ROOT][..]` index
869+
[COMPILING] bar v0.1.0 ([CWD]/bar)
870+
[COMPILING] foo v0.0.1 ([CWD])
871+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
872+
",
873+
)
874+
.run();
875+
p.cargo("build")
876+
.with_stderr(
877+
"\
878+
[WARNING] patch for `bar` uses the features mechanism. \
879+
default-features and features will not take effect because the patch dependency does not support this mechanism
880+
[FINISHED] [..]
881+
",
882+
)
883+
.run();
884+
}
885+
790886
#[cargo_test]
791887
fn no_warn_ws_patch() {
792888
Package::new("c", "0.1.0").publish();

0 commit comments

Comments
 (0)