Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/cargo/core/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,23 @@ impl<'gctx> PackageRegistry<'gctx> {
dep.package_name()
);

if dep.features().len() != 0 || !dep.uses_default_features() {
self.source_config.gctx().shell().warn(format!(
"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 unused_fields = Vec::new();
if dep.features().len() != 0 {
unused_fields.push("`features`");
}
if !dep.uses_default_features() {
unused_fields.push("`default-features`")
}
if !unused_fields.is_empty() {
let mut shell = self.source_config.gctx().shell();
shell.warn(format!(
"unused field in patch for `{}`: {}",
dep.package_name(),
unused_fields.join(", ")
))?;
shell.note(format!(
"configure {} in the `dependencies` entry",
unused_fields.join(", ")
))?;
}

Expand Down
26 changes: 18 additions & 8 deletions src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,24 @@ pub fn resolve_ws_with_opts<'gctx>(
.warn(format!("package replacement is not used: {}", replace_spec))?
}

if dep.features().len() != 0 || !dep.uses_default_features() {
ws.gctx()
.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()
))?
let mut unused_fields = Vec::new();
if dep.features().len() != 0 {
unused_fields.push("`features`");
}
if !dep.uses_default_features() {
unused_fields.push("`default-features`")
}
if !unused_fields.is_empty() {
let mut shell = ws.gctx().shell();
shell.warn(format!(
"unused field in replacement for `{}`: {}",
dep.package_name(),
unused_fields.join(", ")
))?;
shell.note(format!(
"configure {} in the `dependencies` entry",
unused_fields.join(", ")
))?;
}
}

Expand Down
36 changes: 24 additions & 12 deletions tests/testsuite/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,20 +928,26 @@ fn add_patch_with_features() {
.file("bar/src/lib.rs", r#""#)
.build();

p.cargo("check").with_stderr_data(str![[r#"
[WARNING] patch for `bar` uses the features mechanism. default-features and features will not take effect because the patch dependency does not support this mechanism
p.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] unused field in patch for `bar`: `features`
[NOTE] configure `features` in the `dependencies` entry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this to make two sentences more connected?

Suggested change
[NOTE] configure `features` in the `dependencies` entry
[NOTE] configure `features` in the `[dependencies]` entry instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would take the two sentences and make them one which imo doesn't quite fit with this style of messages.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]).run();
p.cargo("check").with_stderr_data(str![[r#"
[WARNING] patch for `bar` uses the features mechanism. default-features and features will not take effect because the patch dependency does not support this mechanism
"#]])
.run();
p.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] unused field in patch for `bar`: `features`
[NOTE] configure `features` in the `dependencies` entry
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]).run();
"#]])
.run();
}

#[cargo_test]
Expand Down Expand Up @@ -970,20 +976,26 @@ fn add_patch_with_setting_default_features() {
.file("bar/src/lib.rs", r#""#)
.build();

p.cargo("check").with_stderr_data(str![[r#"
[WARNING] patch for `bar` uses the features mechanism. default-features and features will not take effect because the patch dependency does not support this mechanism
p.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] unused field in patch for `bar`: `features`, `default-features`
[NOTE] configure `features`, `default-features` in the `dependencies` entry
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]).run();
p.cargo("check").with_stderr_data(str![[r#"
[WARNING] patch for `bar` uses the features mechanism. default-features and features will not take effect because the patch dependency does not support this mechanism
"#]])
.run();
p.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] unused field in patch for `bar`: `features`, `default-features`
[NOTE] configure `features`, `default-features` in the `dependencies` entry
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]).run();
"#]])
.run();
}

#[cargo_test]
Expand Down
18 changes: 12 additions & 6 deletions tests/testsuite/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,19 @@ fn override_with_features() {
)
.build();

p.cargo("check").with_stderr_data(str![[r#"
p.cargo("check")
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[UPDATING] git repository `[ROOTURL]/override`
[LOCKING] 2 packages to latest compatible versions
[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
[WARNING] unused field in replacement for `bar`: `features`
[NOTE] configure `features` in the `dependencies` entry
[CHECKING] bar v0.1.0 ([ROOTURL]/override#[..])
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]).run();
"#]])
.run();
}

#[cargo_test]
Expand Down Expand Up @@ -136,16 +139,19 @@ fn override_with_setting_default_features() {
)
.build();

p.cargo("check").with_stderr_data(str![[r#"
p.cargo("check")
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[UPDATING] git repository `[ROOTURL]/override`
[LOCKING] 2 packages to latest compatible versions
[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
[WARNING] unused field in replacement for `bar`: `features`, `default-features`
[NOTE] configure `features`, `default-features` in the `dependencies` entry
[CHECKING] bar v0.1.0 ([ROOTURL]/override#[..])
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]).run();
"#]])
.run();
}

#[cargo_test]
Expand Down
Loading