You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Patches in ~/.cargo/config.toml add [[patch.unused]] to Cargo.lock #15130
Personally I don't think that "simply add [patch] to .cargo/config" is viable. The patch table was designed to be in manifests, and having it be in global configuration radically changes the feature and breaks some of the design of the feature in the first place:
Configuration would now add patch.unused to all lock files with projects using the configuration.
Lock files in existing projects will no longer work because patch.unused needs to be inserted.
The same issue I mentioned before where when you check something in it may not work elsewhere. (Note that source replacement is not an exception to this rule, source replacement is heavily documented as "you must reflect the contents of the original source", so if you get a lock file you can't use elsewhere then you're mis-using the source replacement feature)
Resolving a dependency graph is intended to be a project-local decision, not a global system-configuration decision. That's sort of what Cargo has always trended towards.
All that being said there may still be room for a patch-like feature to get added to .cargo/config.toml. I think it would be good to enumerate requirements to see if patch is perhaps overpowered or if a subset of patch should be allowed in .cargo/config.toml
I encountered the issue by creating a ~/.cargo/config.toml as shown in FillZpp/sys-info-rs#118 (comment), and then at some point something tried to do a cargo install with --locked, which failed for the reasons quoted above.
Could you provide more context for your use case? For your cargo install command, do you need the patch? If so, why? Do you need --locked and, if so, why?
What I'm wanting to weigh is the impact and scope of this. In that linked comment, the alternative was to not support the feature at all.
I was wondering a resolver.track-unused-patches = false or something else to stop writing [[patch.unused]] to lockfile?
While rust-analyzer fixes the issue rust-lang/rust-analyzer#19667 by using --lockfile-path, I still feel like this approach is better:
Using --lockfile-path may create a completely new lockfile when no lockfile pre-exists. Stoping tracking unused patches won't.
While Alex said
Resolving a dependency graph is intended to be a project-local decision, not a global system-configuration decision. That's sort of what Cargo has always trended towards.
@weihanglo you spoke to your use case in rust-lang/rust-analyzer#19667, could you carry it forward to here? Currently this is "needs info" as we need more use case information from the existing requester.
Using --lockfile-path may create a completely new lockfile when no lockfile pre-exists. Stoping tracking unused patches won't.
Isn' that up to how people implement things? They can copy over the lockfile and then use it.
why is it that you have a patch in your user config?
The tool I am building leverages [patch] in config for overriding a dependency with a local copy shared between “Cargo workspaces”. You can see it as the tool one level above which interacts and manages multiple Cargo workspaces. The tool use CARGO_HOME to achieve that as @arielb1 has described.
However, the lockfile in every package doesn't care about whether the actual lockfile content is changing. But loading metadata for std workspace is an outlier because
it passes --locked
we don't really want to fetch std's dependencies or re-resolve std.
To summarize some clarifications I got from @weihanglo: When there are unused patches, a section gets added to all Cargo.lock files that are affected. Where unexpected, this could be problematic. When asking how this is dealt with, the answer is basically
They do their own locking for their internal projects so Cargo.lock is ignored
This is a special CARGO_HOME setup just for internal projects by their build tool so this does not negatively affect other projects that do care about their Cargo.lock
Now, looking back on when .cargo/config.tomls [patch] table was under discussion, Alex was concerned about the negative impact on global config (source). Jon had said this was for project-local config and not global config (source). Unsure if the custom CARGO_HOME didn't exist yet or if how it was being used was "local" in Jon's mind but I think there was a disconnect here and we are now dealing with the after affects of that. Alex even expressed concern over "misuse" of this feature (source) and my feeling is that we are in that territory.
Personally, I'd rather we not develop a one-off solution for what feels like an extreme corner case. I feel like we should evaluate unused patches in CARGO_HOME on a case-by-case basis to evaluate what the intended workflow should be. Take #15130 for example. Our options include
Have the user patch the source and install that
Create an install-only config and special handle its unused patches
Find a general solution to unused patches in the user config
The annoyance with --lockfile-path is the need for us to allocate a temp dir / file though :/
Minor annoyance unless the projects are those that can only work on readonly filesystem (which we should fix through #10096 but having a escape hatch here help a bit).
Activity
epage commentedon Feb 3, 2025
Could you provide more context for your use case? For your
cargo installcommand, do you need the patch? If so, why? Do you need--lockedand, if so, why?What I'm wanting to weigh is the impact and scope of this. In that linked comment, the alternative was to not support the feature at all.
epage commentedon Apr 28, 2025
Forgot to add, why is the patch being put in
~/.cargo/config.tomlrather than in a location specific to your repo?weihanglo commentedon Jan 11, 2026
I was wondering a
resolver.track-unused-patches = falseor something else to stop writing[[patch.unused]]to lockfile?While rust-analyzer fixes the issue rust-lang/rust-analyzer#19667 by using
--lockfile-path, I still feel like this approach is better:Using
--lockfile-pathmay create a completely new lockfile when no lockfile pre-exists. Stoping tracking unused patches won't.While Alex said
dependency solving gradually becomes a configurable feature. If one has system-wide patches (for example, my scenario unused
[patch]in$CARGO_HOME/config.tomlfailed loading sysroot metadata rust-analyzer#19667 (comment)), a way to turn of that is useful.epage commentedon Jan 12, 2026
@weihanglo you spoke to your use case in rust-lang/rust-analyzer#19667, could you carry it forward to here? Currently this is "needs info" as we need more use case information from the existing requester.
Isn' that up to how people implement things? They can copy over the lockfile and then use it.
weihanglo commentedon Jan 12, 2026
Commented by weihanglo in rust-lang/rust-analyzer#19667 (comment)
Commented by epage in rust-lang/rust-analyzer#19667 (comment)
weihanglo commentedon Jan 12, 2026
Yeah but in rust-lang/rust-analyzer#19667 (comment):
Minor annoyance unless the projects are those that can only work on readonly filesystem (which we should fix through #10096 but having a escape hatch here help a bit).