Skip to content

Commit aecb40b

Browse files
committed
fix(toml): Remove underscore field support in 2024
This is part of the 2024 Edition and is part of rust-lang/rust#123754 and #13629
1 parent b81f94a commit aecb40b

File tree

3 files changed

+485
-15
lines changed

3 files changed

+485
-15
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,9 @@ fn resolve_toml(
349349
"dev-dependencies",
350350
package_name,
351351
"package",
352+
edition,
352353
warnings,
353-
);
354+
)?;
354355
resolved_toml.dev_dependencies = resolve_dependencies(
355356
gctx,
356357
edition,
@@ -368,8 +369,9 @@ fn resolve_toml(
368369
"build-dependencies",
369370
package_name,
370371
"package",
372+
edition,
371373
warnings,
372-
);
374+
)?;
373375
resolved_toml.build_dependencies = resolve_dependencies(
374376
gctx,
375377
edition,
@@ -400,8 +402,9 @@ fn resolve_toml(
400402
"dev-dependencies",
401403
name,
402404
"platform target",
405+
edition,
403406
warnings,
404-
);
407+
)?;
405408
let resolved_dev_dependencies = resolve_dependencies(
406409
gctx,
407410
edition,
@@ -419,8 +422,9 @@ fn resolve_toml(
419422
"build-dependencies",
420423
name,
421424
"platform target",
425+
edition,
422426
warnings,
423-
);
427+
)?;
424428
let resolved_build_dependencies = resolve_dependencies(
425429
gctx,
426430
edition,
@@ -657,8 +661,9 @@ fn resolve_dependencies<'a>(
657661
"default-features",
658662
name_in_toml,
659663
"dependency",
664+
edition,
660665
warnings,
661-
);
666+
)?;
662667
if d.public.is_some() {
663668
let public_feature = features.require(Feature::public_dependency());
664669
let with_public_feature = public_feature.is_ok();
@@ -2323,9 +2328,13 @@ fn deprecated_underscore<T>(
23232328
new_path: &str,
23242329
name: &str,
23252330
kind: &str,
2331+
edition: Edition,
23262332
warnings: &mut Vec<String>,
2327-
) {
2328-
if old.is_some() && new.is_some() {
2333+
) -> CargoResult<()> {
2334+
if old.is_some() && Edition::Edition2024 <= edition {
2335+
let old_path = new_path.replace("-", "_");
2336+
anyhow::bail!("`{old_path}` is unsupported as of the 2024 edition; instead use `{new_path}`\n(in the `{name}` {kind})");
2337+
} else if old.is_some() && new.is_some() {
23292338
let old_path = new_path.replace("-", "_");
23302339
warnings.push(format!(
23312340
"`{old_path}` is redundant with `{new_path}`, preferring `{new_path}` in the `{name}` {kind}"
@@ -2336,6 +2345,7 @@ fn deprecated_underscore<T>(
23362345
"`{old_path}` is deprecated in favor of `{new_path}` and will not work in the 2024 edition\n(in the `{name}` {kind})"
23372346
))
23382347
}
2348+
Ok(())
23392349
}
23402350

23412351
fn warn_on_unused(unused: &BTreeSet<String>, warnings: &mut Vec<String>) {

src/cargo/util/toml/targets.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ fn resolve_lib(
179179
validate_lib_name(&lib, warnings)?;
180180

181181
// Checking the original lib
182-
validate_proc_macro(&lib, "library", warnings);
183-
validate_crate_types(&lib, "library", warnings);
182+
validate_proc_macro(&lib, "library", edition, warnings)?;
183+
validate_crate_types(&lib, "library", edition, warnings)?;
184184

185185
if lib.path.is_none() {
186186
if let Some(inferred) = inferred {
@@ -632,8 +632,8 @@ fn resolve_targets_with_legacy_path(
632632

633633
for target in &toml_targets {
634634
validate_target_name(target, target_kind_human, target_kind, warnings)?;
635-
validate_proc_macro(target, target_kind_human, warnings);
636-
validate_crate_types(target, target_kind_human, warnings);
635+
validate_proc_macro(target, target_kind_human, edition, warnings)?;
636+
validate_crate_types(target, target_kind_human, edition, warnings)?;
637637
}
638638

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

1101-
fn validate_proc_macro(target: &TomlTarget, kind: &str, warnings: &mut Vec<String>) {
1101+
fn validate_proc_macro(
1102+
target: &TomlTarget,
1103+
kind: &str,
1104+
edition: Edition,
1105+
warnings: &mut Vec<String>,
1106+
) -> CargoResult<()> {
11021107
deprecated_underscore(
11031108
&target.proc_macro2,
11041109
&target.proc_macro,
11051110
"proc-macro",
11061111
name_or_panic(target),
11071112
format!("{kind} target").as_str(),
1113+
edition,
11081114
warnings,
1109-
);
1115+
)
11101116
}
11111117

1112-
fn validate_crate_types(target: &TomlTarget, kind: &str, warnings: &mut Vec<String>) {
1118+
fn validate_crate_types(
1119+
target: &TomlTarget,
1120+
kind: &str,
1121+
edition: Edition,
1122+
warnings: &mut Vec<String>,
1123+
) -> CargoResult<()> {
11131124
deprecated_underscore(
11141125
&target.crate_type2,
11151126
&target.crate_type,
11161127
"crate-type",
11171128
name_or_panic(target),
11181129
format!("{kind} target").as_str(),
1130+
edition,
11191131
warnings,
1120-
);
1132+
)
11211133
}

0 commit comments

Comments
 (0)