Skip to content

Commit 01c5293

Browse files
authored
fix(toml): Report '<target>.edition' deprecation to users (#15321)
### What does this PR try to resolve? This is a part of #15283 In the RFC, I mentioned this might be blocked on #12235. In hindsight, the use of this is [rare enough](https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/Deprecate.20build-target.20.60edition.60.20field.3F/near/499047806) that I suspect we can go ahead and warn without user controllable lints. ### How should we test and review this PR? ### Additional information
2 parents fb3b37b + c13453f commit 01c5293

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

Diff for: src/cargo/util/toml/targets.rs

+23-6
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,28 @@ pub(super) fn to_targets(
7676
normalized_toml.bin.as_deref().unwrap_or_default(),
7777
package_root,
7878
edition,
79+
warnings,
7980
)?);
8081

8182
targets.extend(to_example_targets(
8283
normalized_toml.example.as_deref().unwrap_or_default(),
8384
package_root,
8485
edition,
86+
warnings,
8587
)?);
8688

8789
targets.extend(to_test_targets(
8890
normalized_toml.test.as_deref().unwrap_or_default(),
8991
package_root,
9092
edition,
93+
warnings,
9194
)?);
9295

9396
targets.extend(to_bench_targets(
9497
normalized_toml.bench.as_deref().unwrap_or_default(),
9598
package_root,
9699
edition,
100+
warnings,
97101
)?);
98102

99103
// processing the custom build script
@@ -259,7 +263,7 @@ fn to_lib_target(
259263
};
260264

261265
let mut target = Target::lib_target(name_or_panic(lib), crate_types, path, edition);
262-
configure(lib, &mut target)?;
266+
configure(lib, &mut target, TARGET_KIND_HUMAN_LIB, warnings)?;
263267
target.set_name_inferred(original_lib.map_or(true, |v| v.name.is_none()));
264268
Ok(Some(target))
265269
}
@@ -348,6 +352,7 @@ fn to_bin_targets(
348352
bins: &[TomlBinTarget],
349353
package_root: &Path,
350354
edition: Edition,
355+
warnings: &mut Vec<String>,
351356
) -> CargoResult<Vec<Target>> {
352357
// This loop performs basic checks on each of the TomlTarget in `bins`.
353358
for bin in bins {
@@ -371,7 +376,7 @@ fn to_bin_targets(
371376
edition,
372377
);
373378

374-
configure(bin, &mut target)?;
379+
configure(bin, &mut target, TARGET_KIND_HUMAN_BIN, warnings)?;
375380
result.push(target);
376381
}
377382
Ok(result)
@@ -430,6 +435,7 @@ fn to_example_targets(
430435
targets: &[TomlExampleTarget],
431436
package_root: &Path,
432437
edition: Edition,
438+
warnings: &mut Vec<String>,
433439
) -> CargoResult<Vec<Target>> {
434440
validate_unique_names(&targets, TARGET_KIND_EXAMPLE)?;
435441

@@ -448,7 +454,7 @@ fn to_example_targets(
448454
toml.required_features.clone(),
449455
edition,
450456
);
451-
configure(&toml, &mut target)?;
457+
configure(&toml, &mut target, TARGET_KIND_HUMAN_EXAMPLE, warnings)?;
452458
result.push(target);
453459
}
454460

@@ -487,6 +493,7 @@ fn to_test_targets(
487493
targets: &[TomlTestTarget],
488494
package_root: &Path,
489495
edition: Edition,
496+
warnings: &mut Vec<String>,
490497
) -> CargoResult<Vec<Target>> {
491498
validate_unique_names(&targets, TARGET_KIND_TEST)?;
492499

@@ -499,7 +506,7 @@ fn to_test_targets(
499506
toml.required_features.clone(),
500507
edition,
501508
);
502-
configure(&toml, &mut target)?;
509+
configure(&toml, &mut target, TARGET_KIND_HUMAN_TEST, warnings)?;
503510
result.push(target);
504511
}
505512
Ok(result)
@@ -554,6 +561,7 @@ fn to_bench_targets(
554561
targets: &[TomlBenchTarget],
555562
package_root: &Path,
556563
edition: Edition,
564+
warnings: &mut Vec<String>,
557565
) -> CargoResult<Vec<Target>> {
558566
validate_unique_names(&targets, TARGET_KIND_BENCH)?;
559567

@@ -566,7 +574,7 @@ fn to_bench_targets(
566574
toml.required_features.clone(),
567575
edition,
568576
);
569-
configure(&toml, &mut target)?;
577+
configure(&toml, &mut target, TARGET_KIND_HUMAN_BENCH, warnings)?;
570578
result.push(target);
571579
}
572580

@@ -892,7 +900,12 @@ fn validate_unique_names(targets: &[TomlTarget], target_kind: &str) -> CargoResu
892900
Ok(())
893901
}
894902

895-
fn configure(toml: &TomlTarget, target: &mut Target) -> CargoResult<()> {
903+
fn configure(
904+
toml: &TomlTarget,
905+
target: &mut Target,
906+
target_kind_human: &str,
907+
warnings: &mut Vec<String>,
908+
) -> CargoResult<()> {
896909
let t2 = target.clone();
897910
target
898911
.set_tested(toml.test.unwrap_or_else(|| t2.tested()))
@@ -909,6 +922,10 @@ fn configure(toml: &TomlTarget, target: &mut Target) -> CargoResult<()> {
909922
.set_for_host(toml.proc_macro().unwrap_or_else(|| t2.for_host()));
910923

911924
if let Some(edition) = toml.edition.clone() {
925+
let name = target.name();
926+
warnings.push(format!(
927+
"`edition` is set on {target_kind_human} `{name}` which is deprecated"
928+
));
912929
target.set_edition(
913930
edition
914931
.parse()

Diff for: tests/testsuite/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5404,6 +5404,7 @@ fn target_edition() {
54045404

54055405
p.cargo("build -v")
54065406
.with_stderr_data(str![[r#"
5407+
[WARNING] `edition` is set on library `foo` which is deprecated
54075408
[COMPILING] foo v0.0.1 ([ROOT]/foo)
54085409
[RUNNING] `rustc [..]--edition=2018 [..]`
54095410
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

Diff for: tests/testsuite/freshness.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2255,13 +2255,15 @@ fn edition_change_invalidates() {
22552255
);
22562256
p.cargo("build")
22572257
.with_stderr_data(str![[r#"
2258+
[WARNING] `edition` is set on library `foo` which is deprecated
22582259
[COMPILING] foo v0.1.0 ([ROOT]/foo)
22592260
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
22602261
22612262
"#]])
22622263
.run();
22632264
p.cargo("build -v")
22642265
.with_stderr_data(str![[r#"
2266+
[WARNING] `edition` is set on library `foo` which is deprecated
22652267
[FRESH] foo v0.1.0 ([ROOT]/foo)
22662268
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
22672269

Diff for: tests/testsuite/freshness_checksum.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,7 @@ fn edition_change_invalidates() {
20302030
p.cargo("build -Zchecksum-freshness")
20312031
.masquerade_as_nightly_cargo(&["checksum-freshness"])
20322032
.with_stderr_data(str![[r#"
2033+
[WARNING] `edition` is set on library `foo` which is deprecated
20332034
[COMPILING] foo v0.1.0 ([ROOT]/foo)
20342035
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
20352036
@@ -2038,6 +2039,7 @@ fn edition_change_invalidates() {
20382039
p.cargo("build -Zchecksum-freshness -v")
20392040
.masquerade_as_nightly_cargo(&["checksum-freshness"])
20402041
.with_stderr_data(str![[r#"
2042+
[WARNING] `edition` is set on library `foo` which is deprecated
20412043
[FRESH] foo v0.1.0 ([ROOT]/foo)
20422044
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
20432045

0 commit comments

Comments
 (0)