Skip to content

Commit 4fbc6a9

Browse files
committed
Auto merge of #12903 - epage:docs-deps, r=weihanglo
docs(ref): Highlight commands to answer dep resolution questions Previously, in the #6666, the aptly named `cargo lucifer` was suggested for answering resolver questions. Turns out most of these can be answered now, between logging and `cargo tree`. This adds troubleshooting tips to help highlight the use of these commands to answer these questions. Fixes #6666
2 parents b4d18d4 + 086d16c commit 4fbc6a9

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/doc/src/reference/resolver.md

+46-1
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,43 @@ break the build.
489489
The following illustrates some problems you may experience, and some possible
490490
solutions.
491491

492+
### Why was a dependency included?
493+
494+
Say you see dependency `rand` in the `cargo check` output but don't think its needed and want to understand why its being pulled in.
495+
496+
You can run
497+
```console
498+
$ cargo tree --workspace --target all --all-features --invert rand
499+
rand v0.8.5
500+
└── ...
501+
502+
rand v0.8.5
503+
└── ...
504+
```
505+
506+
You might identify that it was an activated feature that caused `rand` to show up. To figure out which package activated the feature, you can add the `--edges features`
507+
```console
508+
$ cargo tree --workspace --target all --all-features --edges features --invert rand
509+
rand v0.8.5
510+
└── ...
511+
512+
rand v0.8.5
513+
└── ...
514+
```
515+
492516
### Unexpected dependency duplication
493517

494-
The resolver algorithm may converge on a solution that includes two copies of a
518+
You see multiple instances of `rand` when you run
519+
```console
520+
$ cargo tree --workspace --target all --all-features --duplicates
521+
rand v0.7.3
522+
└── ...
523+
524+
rand v0.8.5
525+
└── ...
526+
```
527+
528+
The resolver algorithm has converged on a solution that includes two copies of a
495529
dependency when one would suffice. For example:
496530

497531
```toml
@@ -517,6 +551,17 @@ But, if you run into this situation, the [`cargo update`] command with the
517551

518552
[`cargo update`]: ../commands/cargo-update.md
519553

554+
### Why wasn't a newer version selected?
555+
556+
Say you noticed that the latest version of a dependency wasn't selected when you ran:
557+
```console
558+
$ cargo update
559+
```
560+
You can enable some extra logging to see why this happened:
561+
```console
562+
$ env CARGO_LOG=cargo::core::resolver=trace cargo update
563+
```
564+
**Note:** Cargo log targets and levels may change over time.
520565

521566
### SemVer-breaking patch release breaks the build
522567

0 commit comments

Comments
 (0)