.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;
// 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
.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
};
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
.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
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(
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,
+ );
}
}
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,
+ );
}
}
.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();
}
.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();
}
.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();
}
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();
}
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());
}
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();