Skip to content

Commit e5f941d

Browse files
committed
Auto merge of #12185 - QiangHeisenberg:faq, r=weihanglo
Add a description of `Cargo.lock` conflicts in the Cargo FAQ ### What does this PR try to resolve? Add a message for issue #12079. For detailed discussion, please refer to:#12092
2 parents c412aa4 + b80d902 commit e5f941d

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/doc/src/faq.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,49 @@ Some issues we've seen historically which can cause crates to get rebuilt are:
259259
If after trying to debug your issue, however, you're still running into problems
260260
then feel free to [open an
261261
issue](https://github.com/rust-lang/cargo/issues/new)!
262+
263+
### What does "version conflict" mean and how to resolve it?
264+
265+
> failed to select a version for `x` which could resolve this conflict
266+
267+
Have you seen the error message above?
268+
269+
This is one of the most annoying error message for Cargo users. There are several
270+
situations may lead us to a version conflict. Below we'll walk through possible
271+
causes and provide diagnostic techniques to help you out there:
272+
273+
- The project and its dependencies use [links] to repeatedly link the local
274+
library. Cargo forbids linking two packages with the same native library, so
275+
even with multiple layers of dependencies it is not allowed. In this case, the
276+
error message will prompt: `Only one package in the dependency graph may specify
277+
the same links value`, you may need to manually check and delete duplicate link
278+
values. The community also have [conventions in place] to alleviate this.
279+
280+
- When depending on different crates in the project, if these crates use the same
281+
dependent library, but the version used is restricted, making it impossible to
282+
determine the correct version, it will also cause conflicts. The error message
283+
will prompt: `all possible versions conflict with previously selected packages`.
284+
You may need to modify the version requirements to make them consistent.
285+
286+
- If there are multiple versions of dependencies in the project, when using
287+
[`direct-minimal-versions`], the minimum version requirements cannot be met,
288+
which will cause conflicts. You may need to modify version requirements of your
289+
direct dependencies to meet the minimum SemVer version accordingly.
290+
291+
- If the dependent crate does not have the features you choose, it will also
292+
cause conflicts. At this time, you need to check the dependent version and its
293+
features.
294+
295+
- Conflicts may occur when merging branches or PRs, if there are non-trivial
296+
conflicts, you can reset all "yours" changes, fix all other conflicts in the
297+
branch, and then run some cargo command (like `cargo tree` or `cargo check`),
298+
which should re-update the lockfile with your own local changes. If you previously
299+
ran some `cargo update` commands in your branch, you can re-run them that this
300+
time. The community has been looking to resolve merge conflicts with `Cargo.lock`
301+
and `Cargo.toml` using a [custom merge tool].
302+
303+
304+
[links]: https://doc.rust-lang.org/cargo/reference/resolver.html#links
305+
[conventions in place]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#-sys-packages
306+
[`direct-minimal-versions`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#direct-minimal-versions
307+
[custom merge tool]: https://github.com/rust-lang/cargo/issues/1818

0 commit comments

Comments
 (0)