@@ -259,3 +259,49 @@ Some issues we've seen historically which can cause crates to get rebuilt are:
259
259
If after trying to debug your issue, however, you're still running into problems
260
260
then feel free to [ open an
261
261
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