Skip to content

Commit 8a925ac

Browse files
authored
fix(config-include): remove support of single string shorthand (#16298)
This was discussed in 2025-11-25 t-cargo meeting. Part of #7723 and #16284
2 parents dce5a6b + 17926f8 commit 8a925ac

File tree

4 files changed

+30
-34
lines changed

4 files changed

+30
-34
lines changed

src/cargo/util/context/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,6 @@ impl GlobalContext {
14431443
table.get("include").map(Cow::Borrowed)
14441444
};
14451445
let includes = match include.map(|c| c.into_owned()) {
1446-
Some(CV::String(s, def)) => vec![ConfigInclude::new(s, def)],
14471446
Some(CV::List(list, _def)) => list
14481447
.into_iter()
14491448
.enumerate()
@@ -1482,7 +1481,7 @@ impl GlobalContext {
14821481
})
14831482
.collect::<CargoResult<Vec<_>>>()?,
14841483
Some(other) => bail!(
1485-
"expected a string or list of strings, but found {} at `include` in `{}",
1484+
"expected a list of strings or a list of tables, but found {} at `include` in `{}",
14861485
other.desc(),
14871486
other.definition()
14881487
),

src/doc/src/reference/unstable.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ For example:
646646

647647
```toml
648648
# .cargo/config.toml
649-
include = "other-config.toml"
649+
include = ["other-config.toml"]
650650

651651
[build]
652652
jobs = 4
@@ -662,7 +662,7 @@ rustflags = ["-W", "unsafe-code"]
662662

663663
#### `include`
664664

665-
* Type: string, array of strings, or array of tables
665+
* Type: array of strings, or array of tables
666666
* Default: none
667667

668668
Loads additional config files. Paths are relative to the config file that
@@ -671,9 +671,6 @@ includes them. Only paths ending with `.toml` are accepted.
671671
Supports the following formats:
672672

673673
```toml
674-
# single path
675-
include = "path/to/mordor.toml"
676-
677674
# array of paths
678675
include = ["frodo.toml", "samwise.toml"]
679676

tests/testsuite/cargo_config/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ fn includes() {
807807
fs::write(
808808
sub_folder.join("config.toml"),
809809
"
810-
include = 'other.toml'
810+
include = ['other.toml']
811811
[build]
812812
rustflags = [\"--flag-directory\"]
813813
",
@@ -859,7 +859,7 @@ build.rustflags = ["--flag-other"]
859859
860860
# [ROOT]/foo/.cargo/config.toml
861861
build.rustflags = ["--flag-directory"]
862-
include = "other.toml"
862+
include = ["other.toml"]
863863
864864
# [ROOT]/home/.cargo/config.toml
865865
alias.foo = "abc --xyz"

tests/testsuite/config_include.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::config::{GlobalContextBuilder, assert_error, write_config_at, write_c
99
#[cargo_test]
1010
fn gated() {
1111
// Requires -Z flag.
12-
write_config_toml("include='other.toml'");
12+
write_config_toml("include=['other.toml']");
1313
write_config_at(
1414
".cargo/other.toml",
1515
"
@@ -30,7 +30,7 @@ fn simple() {
3030
write_config_at(
3131
".cargo/config.toml",
3232
"
33-
include = 'other.toml'
33+
include = ['other.toml']
3434
key1 = 1
3535
key2 = 2
3636
",
@@ -56,7 +56,7 @@ fn enable_in_unstable_config() {
5656
write_config_at(
5757
".cargo/config.toml",
5858
"
59-
include = 'other.toml'
59+
include = ['other.toml']
6060
key1 = 1
6161
key2 = 2
6262
@@ -84,7 +84,7 @@ fn mix_of_hierarchy_and_include() {
8484
write_config_at(
8585
"foo/.cargo/config.toml",
8686
"
87-
include = 'other.toml'
87+
include = ['other.toml']
8888
key1 = 1
8989
9090
# also make sure unstable flags merge in the correct order
@@ -105,7 +105,7 @@ fn mix_of_hierarchy_and_include() {
105105
write_config_at(
106106
".cargo/config.toml",
107107
"
108-
include = 'other.toml'
108+
include = ['other.toml']
109109
key1 = 3
110110
key2 = 3
111111
key3 = 3
@@ -153,7 +153,7 @@ fn mix_of_hierarchy_and_include_with_enable_in_unstable_config() {
153153
write_config_at(
154154
"foo/.cargo/config.toml",
155155
"
156-
include = 'other.toml'
156+
include = ['other.toml']
157157
key1 = 1
158158
159159
# also make sure unstable flags merge in the correct order
@@ -175,7 +175,7 @@ fn mix_of_hierarchy_and_include_with_enable_in_unstable_config() {
175175
write_config_at(
176176
".cargo/config.toml",
177177
"
178-
include = 'other.toml'
178+
include = ['other.toml']
179179
key1 = 3
180180
key2 = 3
181181
key3 = 3
@@ -220,7 +220,7 @@ fn works_with_cli() {
220220
write_config_at(
221221
".cargo/config.toml",
222222
"
223-
include = 'other.toml'
223+
include = ['other.toml']
224224
[build]
225225
rustflags = ['-W', 'unused']
226226
",
@@ -265,7 +265,7 @@ fn left_to_right_bottom_to_top() {
265265
write_config_at(
266266
".cargo/right-middle.toml",
267267
"
268-
include = 'right-bottom.toml'
268+
include = ['right-bottom.toml']
269269
top = 0
270270
right-middle = 0
271271
",
@@ -281,7 +281,7 @@ fn left_to_right_bottom_to_top() {
281281
write_config_at(
282282
".cargo/left-middle.toml",
283283
"
284-
include = 'left-bottom.toml'
284+
include = ['left-bottom.toml']
285285
top = -2
286286
right-middle = -2
287287
right-bottom = -2
@@ -313,13 +313,13 @@ fn nested_include_resolves_relative_to_including_file() {
313313
write_config_at(
314314
".cargo/config.toml",
315315
"
316-
include = '../config/cargo.toml'
316+
include = ['../config/cargo.toml']
317317
",
318318
);
319319
write_config_at(
320320
"config/cargo.toml",
321321
"
322-
include = 'other.toml'
322+
include = ['other.toml']
323323
middle = 10
324324
",
325325
);
@@ -351,7 +351,7 @@ fn nested_include_resolves_relative_to_including_file() {
351351
#[cargo_test]
352352
fn missing_file() {
353353
// Error when there's a missing file.
354-
write_config_toml("include='missing.toml'");
354+
write_config_toml("include=['missing.toml']");
355355
let gctx = GlobalContextBuilder::new()
356356
.unstable_flag("config-include")
357357
.build_err();
@@ -375,7 +375,7 @@ Caused by:
375375
#[cargo_test]
376376
fn wrong_file_extension() {
377377
// Error when it doesn't end with `.toml`.
378-
write_config_toml("include='config.png'");
378+
write_config_toml("include=['config.png']");
379379
let gctx = GlobalContextBuilder::new()
380380
.unstable_flag("config-include")
381381
.build_err();
@@ -393,9 +393,9 @@ Caused by:
393393
#[cargo_test]
394394
fn cycle() {
395395
// Detects a cycle.
396-
write_config_at(".cargo/config.toml", "include='one.toml'");
397-
write_config_at(".cargo/one.toml", "include='two.toml'");
398-
write_config_at(".cargo/two.toml", "include='config.toml'");
396+
write_config_at(".cargo/config.toml", "include=['one.toml']");
397+
write_config_at(".cargo/one.toml", "include=['two.toml']");
398+
write_config_at(".cargo/two.toml", "include=['config.toml']");
399399
let gctx = GlobalContextBuilder::new()
400400
.unstable_flag("config-include")
401401
.build_err();
@@ -433,7 +433,7 @@ fn cli_include() {
433433
write_config_at(".cargo/config-foo.toml", "foo = 2");
434434
let gctx = GlobalContextBuilder::new()
435435
.unstable_flag("config-include")
436-
.config_arg("include='.cargo/config-foo.toml'")
436+
.config_arg("include=['.cargo/config-foo.toml']")
437437
.build();
438438
assert_eq!(gctx.get::<i32>("foo").unwrap(), 2);
439439
assert_eq!(gctx.get::<i32>("bar").unwrap(), 2);
@@ -452,7 +452,7 @@ fn bad_format() {
452452
could not load Cargo configuration
453453
454454
Caused by:
455-
expected a string or list of strings, but found integer at `include` in `[ROOT]/.cargo/config.toml
455+
expected a list of strings or a list of tables, but found integer at `include` in `[ROOT]/.cargo/config.toml
456456
"#]],
457457
);
458458
}
@@ -462,7 +462,7 @@ fn cli_include_failed() {
462462
// Error message when CLI include fails to load.
463463
let gctx = GlobalContextBuilder::new()
464464
.unstable_flag("config-include")
465-
.config_arg("include='foobar.toml'")
465+
.config_arg("include=['foobar.toml']")
466466
.build_err();
467467
assert_error(
468468
gctx.unwrap_err(),
@@ -493,7 +493,7 @@ fn cli_merge_failed() {
493493
);
494494
let gctx = GlobalContextBuilder::new()
495495
.unstable_flag("config-include")
496-
.config_arg("include='.cargo/other.toml'")
496+
.config_arg("include=['.cargo/other.toml']")
497497
.build_err();
498498
// Maybe this error message should mention it was from an include file?
499499
assert_error(
@@ -520,13 +520,13 @@ fn cli_include_take_priority_over_env() {
520520
let gctx = GlobalContextBuilder::new()
521521
.env("CARGO_K", "env")
522522
.unstable_flag("config-include")
523-
.config_arg("include='.cargo/include.toml'")
523+
.config_arg("include=['.cargo/include.toml']")
524524
.build();
525525
assert_eq!(gctx.get::<String>("k").unwrap(), "include");
526526

527527
// k=env
528528
// --config '.cargo/foo.toml'
529-
write_config_at(".cargo/foo.toml", "include='include.toml'");
529+
write_config_at(".cargo/foo.toml", "include=['include.toml']");
530530
let gctx = GlobalContextBuilder::new()
531531
.env("CARGO_K", "env")
532532
.unstable_flag("config-include")
@@ -728,7 +728,7 @@ Caused by:
728728
#[cargo_test]
729729
fn disallow_glob_syntax() {
730730
// Reserved for future extension
731-
write_config_toml("include = 'config-*.toml'");
731+
write_config_toml("include = ['config-*.toml']");
732732
let gctx = GlobalContextBuilder::new()
733733
.unstable_flag("config-include")
734734
.build_err();
@@ -746,7 +746,7 @@ Caused by:
746746
#[cargo_test]
747747
fn disallow_template_syntax() {
748748
// Reserved for future extension
749-
write_config_toml("include = '{workspace-root}/config.toml'");
749+
write_config_toml("include = ['{workspace-root}/config.toml']");
750750
let gctx = GlobalContextBuilder::new()
751751
.unstable_flag("config-include")
752752
.build_err();

0 commit comments

Comments
 (0)