Skip to content

fix(config): --config use same layers merge as config files - #17780

Merged
epage merged 8 commits into
rust-lang:masterfrom
weihanglo:config-merge-layers
Nov 20, 2026
Merged

epage merged 8 commits into
rust-lang:masterfrom
weihanglo:config-merge-layers

Conversation

@weihanglo

Copy link
Copy Markdown
Member

What does this PR try to resolve?

After this, --config load and merge now uses the same underlying mechanism as config files. It is just another store layer and no longer special.

This is mostly a refactor PR, but it does comes with some user-visible error messages changes:

  • It has the same swap like fix(context): merge files and --config as layers #17775 in merge failure, where high precedence item shows up first.
  • The other is "failed to load config from [ROOT]/cli.toml" becomes "failed to merge --config argument cli.toml", which I think is clearer (also due to the change how we load includes from --config)

Also MergePriority got removed in this PR.

Notes to reviewers

This is the main PR before moving ConfigLoader to cargo-util-config.
The rest is moving code and rename the API I believe.

I hope this doesn't step on on Ed's toes too hard :)


🤖 LLM involvement: LLM did a great job at splitting commits for me. What I need to do is shareing the epage PR style page, and show some well-split PR from Ed and :shipit:. Also used for directed prototyping.

There are so many way to die with `--config` + include.
We are not goint to change the behabior but the diagnostics,
so we capture the current one here first.
To reuse `load_unmerged_file` also in `--config` loading,
We need to thread `DefinitionKind` in it,
letting caller tell the initial source of the config loading
This is prepared for `--config` to load `include`s.
`--config` now loads `include`s the same way as config files.
This removes the remaining merge-while-loading include path.

One user visible change is that
merge failure within one `--config` argument
is now reported as a failure to merge that entire argument,
which IMHO is better
Before, `cargo config get --merged=no` labeled `--config` table with
its root definition, which will become `default` once the table is
built with `ConfigStore::from_layers`.

This labeles explicitly so it could stay `--config cli option`.
`--config` arguments and their includes were merged one by one,
with each incoming value overriding the existing one.
`ConfigStore::from_layers` gives the same result for layers of the same kind,
as ties keep the value from the later layer.

The two sides of a merge conflict are now reported the other way around,
the same as conflicts between config files.
Nothing merges configs with `MergePriority::From` anymore,
Values now always merge by definition priority.

Let's remove code!
@rustbot rustbot added A-configuration Area: cargo config files and env vars S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 20, 2026
@rustbot

rustbot commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Muscraft, @epage, @weihanglo
  • @Muscraft, @epage, @weihanglo expanded to Muscraft, epage, weihanglo
  • Random selection from Muscraft, epage

Comment thread src/context/loader.rs Resolved
@epage
epage added this pull request to the merge queue Nov 20, 2026
Merged via the queue into rust-lang:master with commit e8c1c4a Nov 20, 2026
30 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 20, 2026
@weihanglo
weihanglo deleted the config-merge-layers branch November 20, 2026 21:48
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Nov 22, 2026
Update cargo submodule

28 commits in f93c676e3e7ab1aee08dc95d869700f6b99a1a20..ae8f06eb41b8c4a534d0f280f1b9d287f45ead73
2026-11-15 17:27:10 +0000 to 2026-11-21 04:06:35 +0000
- feat(cargo-util-config): expose config loader (rust-lang/cargo#17781)
- feat(config): Add IncludeConfig (rust-lang/cargo#17782)
- fix(config): `--config` use same layers merge as config files (rust-lang/cargo#17780)
- refactor(config): Move include removal up a layer, making include_paths (rust-lang/cargo#17776)
- Support wasm64-unknown-emscripten (rust-lang/cargo#17620)
- fix(context): merge files and `--config` as layers (rust-lang/cargo#17775)
- fix(config)!: Really ensure no comments are present  (rust-lang/cargo#17774)
- fix(config): list unmerged config in precedence order  (rust-lang/cargo#17773)
- fix(config): Handle parsing dotted keys using TOML keys  (rust-lang/cargo#17770)
- fix(config): Improve config schema by implementing Serialize (rust-lang/cargo#17762)
- fix(config): drop redundant config merge error context (rust-lang/cargo#17769)
- fix(config): keep winning definition for non-mergeable list  (rust-lang/cargo#17766)
- test(build-analysis): update for new section timing order (rust-lang/cargo#17767)
- docs(ref): Deprecate 'workspace.package.authors' (rust-lang/cargo#16951)
- Fix git checkout long paths (rust-lang/cargo#17752)
- fix(config): layer loads to work the same as merged load  (rust-lang/cargo#17761)
- refactor(config): Switch another location to `resolve` (rust-lang/cargo#17760)
- refactor(config): Cleanup IncludeConfig by adding ConfigParentRelativePath (rust-lang/cargo#17759)
- docs(lints): Remove nonexistent lints from cargo::default desc (rust-lang/cargo#17757)
- Add period to cargo-toml-vs-cargo-lock.md for clarity. (rust-lang/cargo#17754)
- fix(config)!: Be more explicit about what ConfigRelativePaths are relative to (rust-lang/cargo#17751)
- Fix ‘dependencoes’ typos (rust-lang/cargo#17753)
- refactor(credential)!: replace time with `[email protected]` (rust-lang/cargo#17750)
- refactor(context): miscellaneous loader cleanup (rust-lang/cargo#17747)
- docs(profiles): fix outdated default (rust-lang/cargo#17748)
- chore(config): migrate Renovate config (rust-lang/cargo#17746)
- refactor(context): a `ConfigLoader` type (rust-lang/cargo#17745)
- refactor: modernize with 1.100 API (rust-lang/cargo#17728)
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Nov 22, 2026
Update cargo submodule

28 commits in f93c676e3e7ab1aee08dc95d869700f6b99a1a20..ae8f06eb41b8c4a534d0f280f1b9d287f45ead73
2026-11-15 17:27:10 +0000 to 2026-11-21 04:06:35 +0000
- feat(cargo-util-config): expose config loader (rust-lang/cargo#17781)
- feat(config): Add IncludeConfig (rust-lang/cargo#17782)
- fix(config): `--config` use same layers merge as config files (rust-lang/cargo#17780)
- refactor(config): Move include removal up a layer, making include_paths (rust-lang/cargo#17776)
- Support wasm64-unknown-emscripten (rust-lang/cargo#17620)
- fix(context): merge files and `--config` as layers (rust-lang/cargo#17775)
- fix(config)!: Really ensure no comments are present  (rust-lang/cargo#17774)
- fix(config): list unmerged config in precedence order  (rust-lang/cargo#17773)
- fix(config): Handle parsing dotted keys using TOML keys  (rust-lang/cargo#17770)
- fix(config): Improve config schema by implementing Serialize (rust-lang/cargo#17762)
- fix(config): drop redundant config merge error context (rust-lang/cargo#17769)
- fix(config): keep winning definition for non-mergeable list  (rust-lang/cargo#17766)
- test(build-analysis): update for new section timing order (rust-lang/cargo#17767)
- docs(ref): Deprecate 'workspace.package.authors' (rust-lang/cargo#16951)
- Fix git checkout long paths (rust-lang/cargo#17752)
- fix(config): layer loads to work the same as merged load  (rust-lang/cargo#17761)
- refactor(config): Switch another location to `resolve` (rust-lang/cargo#17760)
- refactor(config): Cleanup IncludeConfig by adding ConfigParentRelativePath (rust-lang/cargo#17759)
- docs(lints): Remove nonexistent lints from cargo::default desc (rust-lang/cargo#17757)
- Add period to cargo-toml-vs-cargo-lock.md for clarity. (rust-lang/cargo#17754)
- fix(config)!: Be more explicit about what ConfigRelativePaths are relative to (rust-lang/cargo#17751)
- Fix ‘dependencoes’ typos (rust-lang/cargo#17753)
- refactor(credential)!: replace time with `[email protected]` (rust-lang/cargo#17750)
- refactor(context): miscellaneous loader cleanup (rust-lang/cargo#17747)
- docs(profiles): fix outdated default (rust-lang/cargo#17748)
- chore(config): migrate Renovate config (rust-lang/cargo#17746)
- refactor(context): a `ConfigLoader` type (rust-lang/cargo#17745)
- refactor: modernize with 1.100 API (rust-lang/cargo#17728)
@rustbot rustbot added this to the 1.102.0 milestone Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-configuration Area: cargo config files and env vars

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants