Skip to content

Commit 2a7c496

Browse files
authored
docs(config-include): prepare for doc stabilization (#16301)
### What does this PR try to resolve? Discussed in 2025-11-25 t-cargo meeting. We prefer inline tables over array of tables for `include`. * `include` is special and should appear early in config files, before other configuration keys * Array-of-tables syntax allows interleaving with other config, which creates confusion about merge order and precedence * Inline tables keep all `include` declarations together at the top, making the load order behavior clearer Part of #7723 and #16284 ### How to test and review this PR?
2 parents 8a925ac + 18eae16 commit 2a7c496

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

src/doc/src/reference/unstable.md

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -660,49 +660,60 @@ rustflags = ["-W", "unsafe-code"]
660660

661661
### Documentation updates
662662

663-
#### `include`
663+
> put this after `## Command-line overrides` before `## Config-relative paths`
664+
> to emphasize its special nature than other config keys.
664665
665-
* Type: array of strings, or array of tables
666+
#### Including extra configuration files
667+
668+
Configuration can include other configuration files using the top-level `include` key.
669+
This allows sharing configuration across multiple projects
670+
or splitting complex configurations into multiple files.
671+
672+
##### `include`
673+
674+
* Type: array of strings or tables
666675
* Default: none
676+
* Environment: not supported
667677

668-
Loads additional config files. Paths are relative to the config file that
669-
includes them. Only paths ending with `.toml` are accepted.
678+
Loads additional configuration files.
679+
Paths are relative to the configuration file that includes them.
680+
Only paths ending with `.toml` are accepted.
670681

671682
Supports the following formats:
672683

673684
```toml
674685
# array of paths
675-
include = ["frodo.toml", "samwise.toml"]
676-
677-
# inline tables
678686
include = [
679-
"simple.toml",
680-
{ path = "optional.toml", optional = true }
687+
"frodo.toml",
688+
"samwise.toml",
681689
]
682690

683-
# array of tables
684-
[[include]]
685-
path = "required.toml"
686-
687-
[[include]]
688-
path = "optional.toml"
689-
optional = true
691+
# inline tables for more control
692+
include = [
693+
{ path = "required.toml" },
694+
{ path = "optional.toml", optional = true },
695+
]
690696
```
691697

692-
When using table syntax (inline tables or array of tables), the following
693-
fields are supported:
698+
> **Note:** For better readability and to avoid confusion, it is recommended to:
699+
> - Place `include` at the top of the configuration file
700+
> - Put one include per line for clearer version control diffs
701+
> - Use inline table syntax when optional includes are needed
702+
703+
When using table syntax, the following fields are supported:
694704

695705
* `path` (string, required): Path to the config file to include.
696706
* `optional` (boolean, default: false): If `true`, missing files are silently
697707
skipped instead of causing an error.
698708

699709
The merge behavior of `include` is different from other config values:
700710

701-
1. Config values are first loaded from the `include` path.
702-
* If `include` is an array, config values are loaded and merged from left
703-
to right for each path.
711+
1. Config values are first loaded from the `include` paths.
712+
* Included files are loaded left to right,
713+
with values from later files taking precedence over earlier ones.
704714
* This step recurses if included config files also contain `include` keys.
705-
2. Then, the config file's own values are merged on top of the included config.
715+
2. Then, the config file's own values are merged on top of the included config,
716+
taking highest precedence.
706717

707718
## target-applies-to-host
708719
* Original Pull Request: [#9322](https://github.com/rust-lang/cargo/pull/9322)

0 commit comments

Comments
 (0)