From 154f372b6b5b543ad04bc7e82eb1c5fc41190621 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 9 Feb 2022 21:59:26 +0800 Subject: [PATCH] Warning on conflicting dev-dependencies keys Signed-off-by: hi-rustin --- src/cargo/util/toml/mod.rs | 7 +++++++ tests/testsuite/build.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 22447668f..f52054736 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1264,6 +1264,13 @@ impl TomlManifest { // Collect the dependencies. process_dependencies(&mut cx, me.dependencies.as_ref(), None)?; + if me.dev_dependencies.is_some() && me.dev_dependencies2.is_some() { + cx.warnings.push(format!( + "found both `dev-dependencies` and `dev_dependencies` are set \ + in the `{}` package", + package_name + )); + } let dev_deps = me .dev_dependencies .as_ref() diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 43eb3ec8e..471cc3476 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -1676,6 +1676,41 @@ Caused by: .run(); } +#[cargo_test] +fn dev_dependencies_conflicting_warning() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2018" + + [dev-dependencies] + a = {path = "a"} + [dev_dependencies] + a = {path = "a"} + "#, + ) + .file("src/lib.rs", "") + .file( + "a/Cargo.toml", + r#" + [package] + name = "a" + version = "0.0.1" + "#, + ) + .file("a/src/lib.rs", "") + .build(); + p.cargo("build") + .with_stderr_contains( + "[WARNING] found both `dev-dependencies` and `dev_dependencies` are set in the `foo` package", + ) + .run(); +} + #[cargo_test] fn lib_crate_types_conflicting_warning() { let p = project()