Skip to content

Commit 8b895cc

Browse files
committed
Use warn_on_deprecated
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
1 parent b295e2f commit 8b895cc

File tree

4 files changed

+53
-54
lines changed

4 files changed

+53
-54
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ pub fn parse_document(
180180
.map_err(|e| anyhow::Error::from(e).context("could not parse input as TOML"))
181181
}
182182

183+
/// Warn about paths that have been deprecated and may conflict.
184+
fn warn_on_deprecated(new_path: &str, name: &str, kind: &str, warnings: &mut Vec<String>) {
185+
let old_path = new_path.replace("-", "_");
186+
warnings.push(format!(
187+
"conflicting between `{new_path}` and `{old_path}` in the `{name}` {kind}.\n
188+
`{old_path}` is ignored and not recommended for use in the future"
189+
))
190+
}
191+
183192
type TomlLibTarget = TomlTarget;
184193
type TomlBinTarget = TomlTarget;
185194
type TomlExampleTarget = TomlTarget;
@@ -1265,23 +1274,15 @@ impl TomlManifest {
12651274
// Collect the dependencies.
12661275
process_dependencies(&mut cx, me.dependencies.as_ref(), None)?;
12671276
if me.dev_dependencies.is_some() && me.dev_dependencies2.is_some() {
1268-
cx.warnings.push(format!(
1269-
"found both `dev-dependencies` and `dev_dependencies` are set \
1270-
in the `{}` package",
1271-
package_name
1272-
));
1277+
warn_on_deprecated("dev-dependencies", package_name, "package", cx.warnings);
12731278
}
12741279
let dev_deps = me
12751280
.dev_dependencies
12761281
.as_ref()
12771282
.or_else(|| me.dev_dependencies2.as_ref());
12781283
process_dependencies(&mut cx, dev_deps, Some(DepKind::Development))?;
12791284
if me.build_dependencies.is_some() && me.build_dependencies2.is_some() {
1280-
cx.warnings.push(format!(
1281-
"found both `build-dependencies` and `build_dependencies` are set \
1282-
in the `{}` package",
1283-
package_name
1284-
));
1285+
warn_on_deprecated("build-dependencies", package_name, "package", cx.warnings);
12851286
}
12861287
let build_deps = me
12871288
.build_dependencies
@@ -1297,23 +1298,15 @@ impl TomlManifest {
12971298
};
12981299
process_dependencies(&mut cx, platform.dependencies.as_ref(), None)?;
12991300
if platform.build_dependencies.is_some() && platform.build_dependencies2.is_some() {
1300-
cx.warnings.push(format!(
1301-
"found both `build-dependencies` and `build_dependencies` are set \
1302-
in the `{}` platform target",
1303-
name
1304-
));
1301+
warn_on_deprecated("build-dependencies", name, "platform target", cx.warnings);
13051302
}
13061303
let build_deps = platform
13071304
.build_dependencies
13081305
.as_ref()
13091306
.or_else(|| platform.build_dependencies2.as_ref());
13101307
process_dependencies(&mut cx, build_deps, Some(DepKind::Build))?;
13111308
if platform.dev_dependencies.is_some() && platform.dev_dependencies2.is_some() {
1312-
cx.warnings.push(format!(
1313-
"found both `dev-dependencies` and `dev_dependencies` are set \
1314-
in the `{}` platform target",
1315-
name
1316-
));
1309+
warn_on_deprecated("dev-dependencies", name, "platform target", cx.warnings);
13171310
}
13181311
let dev_deps = platform
13191312
.dev_dependencies
@@ -1937,11 +1930,7 @@ impl<P: ResolveToPath> DetailedTomlDependency<P> {
19371930
let version = self.version.as_deref();
19381931
let mut dep = Dependency::parse(pkg_name, version, new_source_id)?;
19391932
if self.default_features.is_some() && self.default_features2.is_some() {
1940-
cx.warnings.push(format!(
1941-
"found both `default-features` and `default_features` are set \
1942-
in the `{}` dependency",
1943-
name_in_toml
1944-
));
1933+
warn_on_deprecated("default-features", name_in_toml, "dependency", cx.warnings);
19451934
}
19461935
dep.set_features(self.features.iter().flatten())
19471936
.set_default_features(
@@ -2094,11 +2083,12 @@ impl TomlTarget {
20942083

20952084
fn validate_proc_macro(&self, warnings: &mut Vec<String>) {
20962085
if self.proc_macro_raw.is_some() && self.proc_macro_raw2.is_some() {
2097-
warnings.push(format!(
2098-
"found both `proc-macro` and `proc_macro` are set \
2099-
in the `{}` library target",
2100-
self.name()
2101-
));
2086+
warn_on_deprecated(
2087+
"proc-macro",
2088+
self.name().as_str(),
2089+
"library target",
2090+
warnings,
2091+
);
21022092
}
21032093
}
21042094

@@ -2115,12 +2105,12 @@ impl TomlTarget {
21152105

21162106
fn validate_crate_types(&self, target_kind_human: &str, warnings: &mut Vec<String>) {
21172107
if self.crate_type.is_some() && self.crate_type2.is_some() {
2118-
warnings.push(format!(
2119-
"found both `crate-type` and `crate_type` are set \
2120-
in the `{}` {} target",
2121-
self.name(),
2122-
target_kind_human
2123-
));
2108+
warn_on_deprecated(
2109+
"crate-type",
2110+
self.name().as_str(),
2111+
format!("{target_kind_human} target").as_str(),
2112+
warnings,
2113+
);
21242114
}
21252115
}
21262116

tests/testsuite/build.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,9 +1705,10 @@ fn dev_dependencies_conflicting_warning() {
17051705
.file("a/src/lib.rs", "")
17061706
.build();
17071707
p.cargo("build")
1708-
.with_stderr_contains(
1709-
"[WARNING] found both `dev-dependencies` and `dev_dependencies` are set in the `foo` package",
1710-
)
1708+
.with_stderr_contains(
1709+
"[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `foo` package.\n
1710+
`dev_dependencies` is ignored and not recommended for use in the future"
1711+
)
17111712
.run();
17121713
}
17131714

@@ -1740,9 +1741,10 @@ fn build_dependencies_conflicting_warning() {
17401741
.file("a/src/lib.rs", "")
17411742
.build();
17421743
p.cargo("build")
1743-
.with_stderr_contains(
1744-
"[WARNING] found both `build-dependencies` and `build_dependencies` are set in the `foo` package",
1745-
)
1744+
.with_stderr_contains(
1745+
"[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `foo` package.\n
1746+
`build_dependencies` is ignored and not recommended for use in the future"
1747+
)
17461748
.run();
17471749
}
17481750

@@ -1766,9 +1768,10 @@ fn lib_crate_types_conflicting_warning() {
17661768
.file("src/lib.rs", "pub fn foo() {}")
17671769
.build();
17681770
p.cargo("build")
1769-
.with_stderr_contains(
1770-
"[WARNING] found both `crate-type` and `crate_type` are set in the `foo` library target",
1771-
)
1771+
.with_stderr_contains(
1772+
"[WARNING] conflicting between `crate-type` and `crate_type` in the `foo` library target.\n
1773+
`crate_type` is ignored and not recommended for use in the future",
1774+
)
17721775
.run();
17731776
}
17741777

@@ -1812,8 +1815,10 @@ fn examples_crate_types_conflicting_warning() {
18121815
p.cargo("build")
18131816
.with_stderr_contains(
18141817
"\
1815-
[WARNING] found both `crate-type` and `crate_type` are set in the `ex` example target
1816-
[WARNING] found both `crate-type` and `crate_type` are set in the `goodbye` example target",
1818+
[WARNING] conflicting between `crate-type` and `crate_type` in the `ex` example target.\n
1819+
`crate_type` is ignored and not recommended for use in the future
1820+
[WARNING] conflicting between `crate-type` and `crate_type` in the `goodbye` example target.\n
1821+
`crate_type` is ignored and not recommended for use in the future",
18171822
)
18181823
.run();
18191824
}
@@ -3016,9 +3021,10 @@ fn cargo_platform_specific_dependency_build_dependencies_conflicting_warning() {
30163021

30173022
p.cargo("build")
30183023
.with_stderr_contains(
3019-
format!("[WARNING] found both `build-dependencies` and `build_dependencies` are set in the `{}` platform target", host),
3024+
format!("[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `{}` platform target.\n
3025+
`build_dependencies` is ignored and not recommended for use in the future", host)
30203026
)
3021-
.run();
3027+
.run();
30223028

30233029
assert!(p.bin("foo").is_file());
30243030
}
@@ -3055,9 +3061,10 @@ fn cargo_platform_specific_dependency_dev_dependencies_conflicting_warning() {
30553061

30563062
p.cargo("build")
30573063
.with_stderr_contains(
3058-
format!("[WARNING] found both `dev-dependencies` and `dev_dependencies` are set in the `{}` platform target", host),
3064+
format!("[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `{}` platform target.\n
3065+
`dev_dependencies` is ignored and not recommended for use in the future", host)
30593066
)
3060-
.run();
3067+
.run();
30613068

30623069
assert!(p.bin("foo").is_file());
30633070
p.cargo("test").run();

tests/testsuite/features.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,7 +2102,8 @@ fn default_features_conflicting_warning() {
21022102

21032103
p.cargo("build")
21042104
.with_stderr_contains(
2105-
"[WARNING] found both `default-features` and `default_features` are set in the `a` dependency",
2105+
"[WARNING] conflicting between `default-features` and `default_features` in the `a` dependency.\n
2106+
`default_features` is ignored and not recommended for use in the future"
21062107
)
2107-
.run();
2108+
.run();
21082109
}

tests/testsuite/proc_macro.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ fn proc_macro_conflicting_warning() {
406406

407407
foo.cargo("build")
408408
.with_stderr_contains(
409-
"[WARNING] found both `proc-macro` and `proc_macro` are set in the `foo` library target",
409+
"[WARNING] conflicting between `proc-macro` and `proc_macro` in the `foo` library target.\n
410+
`proc_macro` is ignored and not recommended for use in the future",
410411
)
411412
.run();
412413
}

0 commit comments

Comments
 (0)