Repository navigation
fix(context): merge files and --config as layers - #17775
Conversation
|
r? @epage rustbot has assigned @epage. Use Why was this reviewer chosen?The reviewer was selected based on:
|
--config as layers
| .context("could not load Cargo configuration")?; | ||
| // Merge from highest precedence, so ties keep the value already merged. | ||
| for mut layer in self.load_unmerged_from(path)?.into_iter().rev() { | ||
| layer.values_mut().remove("include"); |
There was a problem hiding this comment.
This got introduced but I'm not seeing the old remove being removed?
There was a problem hiding this comment.
This is needed because the merged view now shares the same code path with cargo config get --merge=no, and the latter passes remove=false to include_paths so no remove at all. We need to remove it at merge time then, otherwise it would show up in cargo config get merged version, as well as in merged ConfigStore (unsure if it should for the latter though, but we should keep the behavior first).
Unsure if we want a regression test, maybe?
BTW once cli merge starts using layer merge the remove argument should be gone.
There was a problem hiding this comment.
Added a test.
BTW once cli merge starts using layer merge the remove argument should be gone.
Also the removal will be only in ConfigStore::from_layers at merge time
There was a problem hiding this comment.
My in-work PR moves the remove call into the caller, so been dealing a bit with this.
Still at bit confused. Didn't you effectively move it into the caller here?
There was a problem hiding this comment.
--config through load_cli_args -> load_includes -> include_paths still pass remove=true so this PR does not yet completely remove that.
Happy to push the whole temporary stack if you want to take a look (still tweaking, rebasing, refacotring though)
Or I can wait and build upon yours, or vice versa, whichever works.
|
aside: Starting to wonder if we should load highest precedence first so there is less reversing everywhere... |
this is a refactor, but doing so swaps the merge base and incoming in error message. Also, a merge failure involving an `include`d file no longer reported with its own line. The later context still gives the full path. I think this is a fine tradeoff. And it is anyway too verbose right now
Before, `--config` values were forced to be on top of the merged config. After, they are now merged by the new `ConfigStore::from_layers`, no longer too special. Some user-observable changes: * A mergeable list set by both a file and `--config` now reports the list container's definition as `--config` This probably doesn't matter that much, but it is consistent with other precedence kinds. * A merge failure between a file and `--config` now calls out `--config` (higher precedence one) first in the error message.
61aa9f4 to
2d5d209
Compare
I guess the switch may be easier when the whole stack is done. I would have one or two more pull requests to get there. |
…ang#17780) ### 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 <rust-lang#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 `include`s 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. Also used for directed prototyping.
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)
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)
What does this PR try to resolve?
After this,
GlobalContextnow builds config from the same layerscargo config get --merged=nodoes.That is, from the new
ConfigStore::from_layers(name open to change)The user visible changes are only in merge-failure errors:
includes and--config,like we already do for different config files
a small regression but it doesn't really add more useful info
(and anyway too verbose ATM)
Final merged values are unchanged.
Notes to reviewers
This is a step toward merging every
ConfigStorelayer in precedence order.🤖 LLM involvement: Prototyping and blessing snapshots.