Skip to content

Commit

Permalink
fix(toml): Remove underscore field support in 2024
Browse files Browse the repository at this point in the history
This is part of the 2024 Edition and is part of rust-lang/rust#123754 and rust-lang#13629
  • Loading branch information
epage committed Apr 25, 2024
1 parent b81f94a commit aecb40b
Show file tree
Hide file tree
Showing 3 changed files with 485 additions and 15 deletions.
24 changes: 17 additions & 7 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,9 @@ fn resolve_toml(
"dev-dependencies",
package_name,
"package",
edition,
warnings,
);
)?;
resolved_toml.dev_dependencies = resolve_dependencies(
gctx,
edition,
Expand All @@ -368,8 +369,9 @@ fn resolve_toml(
"build-dependencies",
package_name,
"package",
edition,
warnings,
);
)?;
resolved_toml.build_dependencies = resolve_dependencies(
gctx,
edition,
Expand Down Expand Up @@ -400,8 +402,9 @@ fn resolve_toml(
"dev-dependencies",
name,
"platform target",
edition,
warnings,
);
)?;
let resolved_dev_dependencies = resolve_dependencies(
gctx,
edition,
Expand All @@ -419,8 +422,9 @@ fn resolve_toml(
"build-dependencies",
name,
"platform target",
edition,
warnings,
);
)?;
let resolved_build_dependencies = resolve_dependencies(
gctx,
edition,
Expand Down Expand Up @@ -657,8 +661,9 @@ fn resolve_dependencies<'a>(
"default-features",
name_in_toml,
"dependency",
edition,
warnings,
);
)?;
if d.public.is_some() {
let public_feature = features.require(Feature::public_dependency());
let with_public_feature = public_feature.is_ok();
Expand Down Expand Up @@ -2323,9 +2328,13 @@ fn deprecated_underscore<T>(
new_path: &str,
name: &str,
kind: &str,
edition: Edition,
warnings: &mut Vec<String>,
) {
if old.is_some() && new.is_some() {
) -> CargoResult<()> {
if old.is_some() && Edition::Edition2024 <= edition {
let old_path = new_path.replace("-", "_");
anyhow::bail!("`{old_path}` is unsupported as of the 2024 edition; instead use `{new_path}`\n(in the `{name}` {kind})");
} else if old.is_some() && new.is_some() {
let old_path = new_path.replace("-", "_");
warnings.push(format!(
"`{old_path}` is redundant with `{new_path}`, preferring `{new_path}` in the `{name}` {kind}"
Expand All @@ -2336,6 +2345,7 @@ fn deprecated_underscore<T>(
"`{old_path}` is deprecated in favor of `{new_path}` and will not work in the 2024 edition\n(in the `{name}` {kind})"
))
}
Ok(())
}

fn warn_on_unused(unused: &BTreeSet<String>, warnings: &mut Vec<String>) {
Expand Down
28 changes: 20 additions & 8 deletions src/cargo/util/toml/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ fn resolve_lib(
validate_lib_name(&lib, warnings)?;

// Checking the original lib
validate_proc_macro(&lib, "library", warnings);
validate_crate_types(&lib, "library", warnings);
validate_proc_macro(&lib, "library", edition, warnings)?;
validate_crate_types(&lib, "library", edition, warnings)?;

if lib.path.is_none() {
if let Some(inferred) = inferred {
Expand Down Expand Up @@ -632,8 +632,8 @@ fn resolve_targets_with_legacy_path(

for target in &toml_targets {
validate_target_name(target, target_kind_human, target_kind, warnings)?;
validate_proc_macro(target, target_kind_human, warnings);
validate_crate_types(target, target_kind_human, warnings);
validate_proc_macro(target, target_kind_human, edition, warnings)?;
validate_crate_types(target, target_kind_human, edition, warnings)?;
}

let mut result = Vec::new();
Expand Down Expand Up @@ -1098,24 +1098,36 @@ fn name_or_panic(target: &TomlTarget) -> &str {
.unwrap_or_else(|| panic!("target name is required"))
}

fn validate_proc_macro(target: &TomlTarget, kind: &str, warnings: &mut Vec<String>) {
fn validate_proc_macro(
target: &TomlTarget,
kind: &str,
edition: Edition,
warnings: &mut Vec<String>,
) -> CargoResult<()> {
deprecated_underscore(
&target.proc_macro2,
&target.proc_macro,
"proc-macro",
name_or_panic(target),
format!("{kind} target").as_str(),
edition,
warnings,
);
)
}

fn validate_crate_types(target: &TomlTarget, kind: &str, warnings: &mut Vec<String>) {
fn validate_crate_types(
target: &TomlTarget,
kind: &str,
edition: Edition,
warnings: &mut Vec<String>,
) -> CargoResult<()> {
deprecated_underscore(
&target.crate_type2,
&target.crate_type,
"crate-type",
name_or_panic(target),
format!("{kind} target").as_str(),
edition,
warnings,
);
)
}

0 comments on commit aecb40b

Please sign in to comment.