Skip to content

refactor(config): Pull out the ConfigStore into its own module - #17614

Merged
weihanglo merged 9 commits into
rust-lang:masterfrom
epage:config
Oct 21, 2026
Merged

weihanglo merged 9 commits into
rust-lang:masterfrom
epage:config

Conversation

@epage

@epage epage commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

What does this PR try to resolve?

This is part of #12883

By pulling out the raw ConfigStore API into its own module, we get a clearer picture of cross-module boundaries for what will eventually be cross-package boundaries.

The next step is to pull out deserialization. Once that is done, there is enough value to pull this all out into a separate package.

Notes to reviewers


🤖 LLM involvement: for trivial refactor steps

@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 Oct 20, 2026
@rustbot

rustbot commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

r? @weihanglo

rustbot has assigned @weihanglo.
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, weihanglo

@rustbot

This comment has been minimized.

Comment thread src/config/definition.rs Resolved
Comment thread src/context/value.rs Outdated
Path,
/// A value defined in an environment variable.
#[expect(dead_code, reason = "file loading does not use environment values")]
Environment,

@weihanglo weihanglo Oct 20, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a plan of setting these two new DefintionKind elsewhere? Without a plan I am not sure what that would be.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these solely because I re-framed this as a <enum>Kind which I felt made the API more cohesive / gave these a better name.

I am wondering about making Definition an opaque type with

  • fn kind(&self) -> DefinitionKind though maybe that would be better named fn precedence(&self) -> Precedence
  • a Source enum which would be File(Path) | Env(String) | None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making it opaque sounds fine to me.

a Source enum which would be File(Path) | Env(String) | None

Better! But still not extremely satisfied. Like our Source for dependencies is the actual source of the dependency, where this is like early mentioned a sticky-bit enum tracking the first loaded source. Our precedent of this is FeaturesFor (which is a bad name unfortunately).

If we cannot come up with a better one, I am good with Source.

Comment thread src/context/value.rs Resolved
epage added 9 commits October 20, 2026 19:20
In working to move `ConfigStore` out,
I realized I had left behind the `config.rs` name instead of naming it
`config_values.rs`.
In preparing that, I realized I should have used a more distinct name
rather than being one letter off from `ConfigValue`.

My main aim for the name is to convey that this is not the actual config
(that is deserialized) but the raw data.
@rustbot

rustbot commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@weihanglo weihanglo left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging and we can bikeshed naming later.

View changes since this review

@weihanglo
weihanglo added this pull request to the merge queue Oct 21, 2026
Merged via the queue into rust-lang:master with commit cf29d0e Oct 21, 2026
30 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 21, 2026
@epage
epage deleted the config branch October 21, 2026 18:44
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Oct 24, 2026
Update cargo submodule

11 commits in 15be64aa0859b5c36f7a86d52f7aa0db44ba4d84..cad07cf8e597397fff5d0f6cb79c9f870c0b1dd2
2026-10-20 16:03:21 +0000 to 2026-10-23 22:04:58 +0000
- build-rs: rename `cargo_target_family` to `cargo_cfg_target_family` (rust-lang/cargo#17636)
- chore: replace `cfg(any())` with `cfg(false)` (rust-lang/cargo#17633)
- feat(timings): peak memory as a column in unit table (rust-lang/cargo#17631)
- Change `build_rs::input::cargo_cfg_target_env` to return `Option` (rust-lang/cargo#17632)
- Update gix to 0.90.0 and adapt Git error recovery (rust-lang/cargo#17578)
- Fix unused dep annotation (rust-lang/cargo#17625)
- fix!: stop uplifting rlibs on nightly  (rust-lang/cargo#17621)
- refactor(config): Pull out the ConfigStore into its own module (rust-lang/cargo#17614)
- test: simplify file content assertions (rust-lang/cargo#17617)
- perf(context): Don't initialize windows-specific code on all platforms (rust-lang/cargo#17615)
- refactor(context): Remove RLS-specific function (rust-lang/cargo#17616)
@rustbot rustbot added this to the 1.101.0 milestone Oct 24, 2026
mehmettoplu-rs pushed a commit to mehmettoplu-rs/miri that referenced this pull request Oct 24, 2026
Update cargo submodule

11 commits in 15be64aa0859b5c36f7a86d52f7aa0db44ba4d84..cad07cf8e597397fff5d0f6cb79c9f870c0b1dd2
2026-10-20 16:03:21 +0000 to 2026-10-23 22:04:58 +0000
- build-rs: rename `cargo_target_family` to `cargo_cfg_target_family` (rust-lang/cargo#17636)
- chore: replace `cfg(any())` with `cfg(false)` (rust-lang/cargo#17633)
- feat(timings): peak memory as a column in unit table (rust-lang/cargo#17631)
- Change `build_rs::input::cargo_cfg_target_env` to return `Option` (rust-lang/cargo#17632)
- Update gix to 0.90.0 and adapt Git error recovery (rust-lang/cargo#17578)
- Fix unused dep annotation (rust-lang/cargo#17625)
- fix!: stop uplifting rlibs on nightly  (rust-lang/cargo#17621)
- refactor(config): Pull out the ConfigStore into its own module (rust-lang/cargo#17614)
- test: simplify file content assertions (rust-lang/cargo#17617)
- perf(context): Don't initialize windows-specific code on all platforms (rust-lang/cargo#17615)
- refactor(context): Remove RLS-specific function (rust-lang/cargo#17616)
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-rust-lang__cargo that referenced this pull request Nov 9, 2026
…g#17699)

### What does this PR try to resolve?

This is part of rust-lang#12883. This builds on rust-lang#17614 and is prep for pulling
the schemas into the config layer. We can then move all of this out into
its own crate as there will be enough meat to it to justify it.

None of these are in the critical path though and can be done over time.

### Notes to reviewers

Github might not handle the code moves well but viewing locally in git
will show that the moves involve minimal changes.

This is not meant to be a complete picture for anything. For example,
- `ConfigReader` should move from public fields to methods to build up
state
- We'll need to eventually move this off of `anyhow`
- Ideally we decouple from `Shell`

I had originally considered abstracting Env through a trait but figured
it is close enough to how config works to move it there.
We can always evaluate a trait later.

---

🤖 LLM involvement: analysis, prototyping, trivial code transformations
Muscraft pushed a commit to Muscraft/cargo that referenced this pull request Nov 14, 2026
### What does this PR try to resolve?

This is a lot of the API polish that was deferred out of rust-lang#17705.

### Notes to reviewers

I was looking at the docs generated by `cargo doc` to help with the
polishing.

Still missing from the API
- Changing the error type
- Dropping `cargo-util-terminal` as a dep
- Cleaning up `Definition` (see
rust-lang#17614 (comment))
- Config discovery and include handling

Still missing generally
- More schema work

Future refactors:
- Switch from `toml_edit` to `toml_parser` for detecting extra syntax
being used

---

🤖 LLM involvement: planning, prototyping, and moving code
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.

4 participants