]> git.proxmox.com Git - cargo.git/commitdiff
Use warn_on_deprecated
authorhi-rustin <rustin.liu@gmail.com>
Wed, 9 Mar 2022 15:54:17 +0000 (23:54 +0800)
committerhi-rustin <rustin.liu@gmail.com>
Wed, 9 Mar 2022 16:08:28 +0000 (00:08 +0800)
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
src/cargo/util/toml/mod.rs
tests/testsuite/build.rs
tests/testsuite/features.rs
tests/testsuite/proc_macro.rs

index 51fc86b9dfc2911f22d6bcb6a44849b58c1b9aa9..9a3a2c4221137fc6e3f2510c106e5932659f74f8 100644 (file)
@@ -180,6 +180,15 @@ pub fn parse_document(
         .map_err(|e| anyhow::Error::from(e).context("could not parse input as TOML"))
 }
 
+/// Warn about paths that have been deprecated and may conflict.
+fn warn_on_deprecated(new_path: &str, name: &str, kind: &str, warnings: &mut Vec<String>) {
+    let old_path = new_path.replace("-", "_");
+    warnings.push(format!(
+        "conflicting between `{new_path}` and `{old_path}` in the `{name}` {kind}.\n
+        `{old_path}` is ignored and not recommended for use in the future"
+    ))
+}
+
 type TomlLibTarget = TomlTarget;
 type TomlBinTarget = TomlTarget;
 type TomlExampleTarget = TomlTarget;
@@ -1265,11 +1274,7 @@ 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
-                ));
+                warn_on_deprecated("dev-dependencies", package_name, "package", cx.warnings);
             }
             let dev_deps = me
                 .dev_dependencies
@@ -1277,11 +1282,7 @@ impl TomlManifest {
                 .or_else(|| me.dev_dependencies2.as_ref());
             process_dependencies(&mut cx, dev_deps, Some(DepKind::Development))?;
             if me.build_dependencies.is_some() && me.build_dependencies2.is_some() {
-                cx.warnings.push(format!(
-                    "found both `build-dependencies` and `build_dependencies` are set \
-                     in the `{}` package",
-                    package_name
-                ));
+                warn_on_deprecated("build-dependencies", package_name, "package", cx.warnings);
             }
             let build_deps = me
                 .build_dependencies
@@ -1297,11 +1298,7 @@ impl TomlManifest {
                 };
                 process_dependencies(&mut cx, platform.dependencies.as_ref(), None)?;
                 if platform.build_dependencies.is_some() && platform.build_dependencies2.is_some() {
-                    cx.warnings.push(format!(
-                        "found both `build-dependencies` and `build_dependencies` are set \
-                         in the `{}` platform target",
-                        name
-                    ));
+                    warn_on_deprecated("build-dependencies", name, "platform target", cx.warnings);
                 }
                 let build_deps = platform
                     .build_dependencies
@@ -1309,11 +1306,7 @@ impl TomlManifest {
                     .or_else(|| platform.build_dependencies2.as_ref());
                 process_dependencies(&mut cx, build_deps, Some(DepKind::Build))?;
                 if platform.dev_dependencies.is_some() && platform.dev_dependencies2.is_some() {
-                    cx.warnings.push(format!(
-                        "found both `dev-dependencies` and `dev_dependencies` are set \
-                         in the `{}` platform target",
-                        name
-                    ));
+                    warn_on_deprecated("dev-dependencies", name, "platform target", cx.warnings);
                 }
                 let dev_deps = platform
                     .dev_dependencies
@@ -1937,11 +1930,7 @@ impl<P: ResolveToPath> DetailedTomlDependency<P> {
         let version = self.version.as_deref();
         let mut dep = Dependency::parse(pkg_name, version, new_source_id)?;
         if self.default_features.is_some() && self.default_features2.is_some() {
-            cx.warnings.push(format!(
-                "found both `default-features` and `default_features` are set \
-                 in the `{}` dependency",
-                name_in_toml
-            ));
+            warn_on_deprecated("default-features", name_in_toml, "dependency", cx.warnings);
         }
         dep.set_features(self.features.iter().flatten())
             .set_default_features(
@@ -2094,11 +2083,12 @@ impl TomlTarget {
 
     fn validate_proc_macro(&self, warnings: &mut Vec<String>) {
         if self.proc_macro_raw.is_some() && self.proc_macro_raw2.is_some() {
-            warnings.push(format!(
-                "found both `proc-macro` and `proc_macro` are set \
-                 in the `{}` library target",
-                self.name()
-            ));
+            warn_on_deprecated(
+                "proc-macro",
+                self.name().as_str(),
+                "library target",
+                warnings,
+            );
         }
     }
 
@@ -2115,12 +2105,12 @@ impl TomlTarget {
 
     fn validate_crate_types(&self, target_kind_human: &str, warnings: &mut Vec<String>) {
         if self.crate_type.is_some() && self.crate_type2.is_some() {
-            warnings.push(format!(
-                "found both `crate-type` and `crate_type` are set \
-                 in the `{}` {} target",
-                self.name(),
-                target_kind_human
-            ));
+            warn_on_deprecated(
+                "crate-type",
+                self.name().as_str(),
+                format!("{target_kind_human} target").as_str(),
+                warnings,
+            );
         }
     }
 
index 59cb97a998db3c358a267fdb3feec2ae6d7f2762..c6ab943e4ba11bf5727f977dc42a05b63ed31a4a 100644 (file)
@@ -1705,9 +1705,10 @@ fn dev_dependencies_conflicting_warning() {
         .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",
-    )
+        .with_stderr_contains(
+"[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `foo` package.\n
+        `dev_dependencies` is ignored and not recommended for use in the future"
+        )
         .run();
 }
 
@@ -1740,9 +1741,10 @@ fn build_dependencies_conflicting_warning() {
         .file("a/src/lib.rs", "")
         .build();
     p.cargo("build")
-    .with_stderr_contains(
-        "[WARNING] found both `build-dependencies` and `build_dependencies` are set in the `foo` package",
-    )
+        .with_stderr_contains(
+"[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `foo` package.\n
+        `build_dependencies` is ignored and not recommended for use in the future"
+        )
         .run();
 }
 
@@ -1766,9 +1768,10 @@ fn lib_crate_types_conflicting_warning() {
         .file("src/lib.rs", "pub fn foo() {}")
         .build();
     p.cargo("build")
-    .with_stderr_contains(
-        "[WARNING] found both `crate-type` and `crate_type` are set in the `foo` library target",
-    )
+        .with_stderr_contains(
+"[WARNING] conflicting between `crate-type` and `crate_type` in the `foo` library target.\n
+        `crate_type` is ignored and not recommended for use in the future",
+        )
         .run();
 }
 
@@ -1812,8 +1815,10 @@ fn examples_crate_types_conflicting_warning() {
     p.cargo("build")
         .with_stderr_contains(
             "\
-[WARNING] found both `crate-type` and `crate_type` are set in the `ex` example target
-[WARNING] found both `crate-type` and `crate_type` are set in the `goodbye` example target",
+[WARNING] conflicting between `crate-type` and `crate_type` in the `ex` example target.\n
+        `crate_type` is ignored and not recommended for use in the future
+[WARNING] conflicting between `crate-type` and `crate_type` in the `goodbye` example target.\n
+        `crate_type` is ignored and not recommended for use in the future",
         )
         .run();
 }
@@ -3016,9 +3021,10 @@ fn cargo_platform_specific_dependency_build_dependencies_conflicting_warning() {
 
     p.cargo("build")
         .with_stderr_contains(
-            format!("[WARNING] found both `build-dependencies` and `build_dependencies` are set in the `{}` platform target", host),
+        format!("[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `{}` platform target.\n
+        `build_dependencies` is ignored and not recommended for use in the future", host)
         )
-            .run();
+        .run();
 
     assert!(p.bin("foo").is_file());
 }
@@ -3055,9 +3061,10 @@ fn cargo_platform_specific_dependency_dev_dependencies_conflicting_warning() {
 
     p.cargo("build")
         .with_stderr_contains(
-        format!("[WARNING] found both `dev-dependencies` and `dev_dependencies` are set in the `{}` platform target", host),
+        format!("[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `{}` platform target.\n
+        `dev_dependencies` is ignored and not recommended for use in the future", host)
         )
-            .run();
+        .run();
 
     assert!(p.bin("foo").is_file());
     p.cargo("test").run();
index 01e06013a15f4aed15a933658e36a231b88d36bc..cc5d10e4045dafff567c28cd4219090b1acf0f92 100644 (file)
@@ -2102,7 +2102,8 @@ fn default_features_conflicting_warning() {
 
     p.cargo("build")
         .with_stderr_contains(
-            "[WARNING] found both `default-features` and `default_features` are set in the `a` dependency",
+"[WARNING] conflicting between `default-features` and `default_features` in the `a` dependency.\n
+        `default_features` is ignored and not recommended for use in the future"
         )
-            .run();
+        .run();
 }
index c40d6a1535b5fa1550841bdb51a0ba0ac872b0e7..50e432a19c8002397de3792578867758554a4f9e 100644 (file)
@@ -406,7 +406,8 @@ fn proc_macro_conflicting_warning() {
 
     foo.cargo("build")
         .with_stderr_contains(
-            "[WARNING] found both `proc-macro` and `proc_macro` are set in the `foo` library target",
+"[WARNING] conflicting between `proc-macro` and `proc_macro` in the `foo` library target.\n
+        `proc_macro` is ignored and not recommended for use in the future",
         )
         .run();
 }