fix(info): Suggest a more universal cargo tree command (#15954)

### What does this PR try to resolve?

Passing a package to `--package` is for workspace members; we need to
pass it to `--invert`.

### How to test and review this PR?

This is part of #14993

While I think we should instead improve the `cargo tree` command to help
users with `--all-features`, we can at least take the other improvement
from #14991.
This commit is contained in:
Weihang Lo 2025-09-12 13:00:22 +00:00 committed by GitHub
commit b10679fc26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 24 additions and 24 deletions

View File

@ -689,9 +689,9 @@ fn print_lockfile_updates(
} }
if ws.gctx().shell().verbosity() == Verbosity::Verbose { if ws.gctx().shell().verbosity() == Verbosity::Verbose {
ws.gctx().shell().note( ws.gctx()
"to see how you depend on a package, run `cargo tree --invert --package <dep>@<ver>`", .shell()
)?; .note("to see how you depend on a package, run `cargo tree --invert <dep>@<ver>`")?;
} else { } else {
if 0 < unchanged_behind { if 0 < unchanged_behind {
ws.gctx().shell().note(format!( ws.gctx().shell().note(format!(

View File

@ -400,7 +400,7 @@ fn suggest_cargo_tree(package_id: PackageId, shell: &mut Shell) -> CargoResult<(
let literal = LITERAL; let literal = LITERAL;
shell.note(format_args!( shell.note(format_args!(
"to see how you depend on {name}, run `{literal}cargo tree --invert --package {name}@{version}{literal:#}`", "to see how you depend on {name}, run `{literal}cargo tree --invert {name}@{version}{literal:#}`",
name = package_id.name(), name = package_id.name(),
version = package_id.version(), version = package_id.version(),
)) ))

View File

@ -1,4 +1,4 @@
<svg width="911px" height="110px" xmlns="http://www.w3.org/2000/svg"> <svg width="827px" height="110px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
@ -25,7 +25,7 @@
</tspan> </tspan>
<tspan x="10px" y="64px"><tspan class="fg-bright-green bold"> Downloaded</tspan><tspan> my-package v0.1.1+my-package (registry `dummy-registry`)</tspan> <tspan x="10px" y="64px"><tspan class="fg-bright-green bold"> Downloaded</tspan><tspan> my-package v0.1.1+my-package (registry `dummy-registry`)</tspan>
</tspan> </tspan>
<tspan x="10px" y="82px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert --package my-package@0.1.1+my-package</tspan><tspan>`</tspan> <tspan x="10px" y="82px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert my-package@0.1.1+my-package</tspan><tspan>`</tspan>
</tspan> </tspan>
<tspan x="10px" y="100px"> <tspan x="10px" y="100px">
</tspan> </tspan>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -1,4 +1,4 @@
<svg width="818px" height="92px" xmlns="http://www.w3.org/2000/svg"> <svg width="740px" height="92px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
@ -23,7 +23,7 @@
</tspan> </tspan>
<tspan x="10px" y="46px"><tspan class="fg-bright-green bold"> Downloaded</tspan><tspan> my-package v1.0.0 (registry `dummy-registry`)</tspan> <tspan x="10px" y="46px"><tspan class="fg-bright-green bold"> Downloaded</tspan><tspan> my-package v1.0.0 (registry `dummy-registry`)</tspan>
</tspan> </tspan>
<tspan x="10px" y="64px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert --package my-package@1.0.0</tspan><tspan>`</tspan> <tspan x="10px" y="64px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert my-package@1.0.0</tspan><tspan>`</tspan>
</tspan> </tspan>
<tspan x="10px" y="82px"> <tspan x="10px" y="82px">
</tspan> </tspan>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,4 +1,4 @@
<svg width="818px" height="56px" xmlns="http://www.w3.org/2000/svg"> <svg width="740px" height="56px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
@ -19,7 +19,7 @@
<rect width="100%" height="100%" y="0" rx="4.5" class="bg" /> <rect width="100%" height="100%" y="0" rx="4.5" class="bg" />
<text xml:space="preserve" class="container fg"> <text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert --package my-package@2.0.0</tspan><tspan>`</tspan> <tspan x="10px" y="28px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert my-package@2.0.0</tspan><tspan>`</tspan>
</tspan> </tspan>
<tspan x="10px" y="46px"> <tspan x="10px" y="46px">
</tspan> </tspan>

Before

Width:  |  Height:  |  Size: 899 B

After

Width:  |  Height:  |  Size: 889 B

View File

@ -1,4 +1,4 @@
<svg width="818px" height="56px" xmlns="http://www.w3.org/2000/svg"> <svg width="740px" height="56px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
@ -19,7 +19,7 @@
<rect width="100%" height="100%" y="0" rx="4.5" class="bg" /> <rect width="100%" height="100%" y="0" rx="4.5" class="bg" />
<text xml:space="preserve" class="container fg"> <text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert --package my-package@2.0.0</tspan><tspan>`</tspan> <tspan x="10px" y="28px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert my-package@2.0.0</tspan><tspan>`</tspan>
</tspan> </tspan>
<tspan x="10px" y="46px"> <tspan x="10px" y="46px">
</tspan> </tspan>

Before

Width:  |  Height:  |  Size: 899 B

After

Width:  |  Height:  |  Size: 889 B

View File

@ -1,4 +1,4 @@
<svg width="818px" height="56px" xmlns="http://www.w3.org/2000/svg"> <svg width="740px" height="56px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
@ -19,7 +19,7 @@
<rect width="100%" height="100%" y="0" rx="4.5" class="bg" /> <rect width="100%" height="100%" y="0" rx="4.5" class="bg" />
<text xml:space="preserve" class="container fg"> <text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert --package my-package@2.0.0</tspan><tspan>`</tspan> <tspan x="10px" y="28px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert my-package@2.0.0</tspan><tspan>`</tspan>
</tspan> </tspan>
<tspan x="10px" y="46px"> <tspan x="10px" y="46px">
</tspan> </tspan>

Before

Width:  |  Height:  |  Size: 899 B

After

Width:  |  Height:  |  Size: 889 B

View File

@ -1,4 +1,4 @@
<svg width="818px" height="110px" xmlns="http://www.w3.org/2000/svg"> <svg width="740px" height="110px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
@ -25,7 +25,7 @@
</tspan> </tspan>
<tspan x="10px" y="64px"><tspan class="fg-bright-green bold"> Downloaded</tspan><tspan> my-package v2.0.0 (registry `dummy-registry`)</tspan> <tspan x="10px" y="64px"><tspan class="fg-bright-green bold"> Downloaded</tspan><tspan> my-package v2.0.0 (registry `dummy-registry`)</tspan>
</tspan> </tspan>
<tspan x="10px" y="82px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert --package my-package@2.0.0</tspan><tspan>`</tspan> <tspan x="10px" y="82px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert my-package@2.0.0</tspan><tspan>`</tspan>
</tspan> </tspan>
<tspan x="10px" y="100px"> <tspan x="10px" y="100px">
</tspan> </tspan>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -1,4 +1,4 @@
<svg width="911px" height="110px" xmlns="http://www.w3.org/2000/svg"> <svg width="827px" height="110px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
@ -25,7 +25,7 @@
</tspan> </tspan>
<tspan x="10px" y="64px"><tspan class="fg-bright-green bold"> Downloaded</tspan><tspan> my-package v0.1.1+my-package (registry `dummy-registry`)</tspan> <tspan x="10px" y="64px"><tspan class="fg-bright-green bold"> Downloaded</tspan><tspan> my-package v0.1.1+my-package (registry `dummy-registry`)</tspan>
</tspan> </tspan>
<tspan x="10px" y="82px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert --package my-package@0.1.1+my-package</tspan><tspan>`</tspan> <tspan x="10px" y="82px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert my-package@0.1.1+my-package</tspan><tspan>`</tspan>
</tspan> </tspan>
<tspan x="10px" y="100px"> <tspan x="10px" y="100px">
</tspan> </tspan>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -1,4 +1,4 @@
<svg width="911px" height="146px" xmlns="http://www.w3.org/2000/svg"> <svg width="827px" height="146px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
@ -30,7 +30,7 @@
</tspan> </tspan>
<tspan x="10px" y="100px"><tspan class="fg-bright-green bold"> Downloaded</tspan><tspan> my-package v0.2.3+my-package (registry `dummy-registry`)</tspan> <tspan x="10px" y="100px"><tspan class="fg-bright-green bold"> Downloaded</tspan><tspan> my-package v0.2.3+my-package (registry `dummy-registry`)</tspan>
</tspan> </tspan>
<tspan x="10px" y="118px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert --package my-package@0.2.3+my-package</tspan><tspan>`</tspan> <tspan x="10px" y="118px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert my-package@0.2.3+my-package</tspan><tspan>`</tspan>
</tspan> </tspan>
<tspan x="10px" y="136px"> <tspan x="10px" y="136px">
</tspan> </tspan>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -1,4 +1,4 @@
<svg width="911px" height="110px" xmlns="http://www.w3.org/2000/svg"> <svg width="827px" height="110px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
@ -25,7 +25,7 @@
</tspan> </tspan>
<tspan x="10px" y="64px"><tspan class="fg-bright-green bold"> Downloaded</tspan><tspan> my-package v0.1.1+my-package (registry `dummy-registry`)</tspan> <tspan x="10px" y="64px"><tspan class="fg-bright-green bold"> Downloaded</tspan><tspan> my-package v0.1.1+my-package (registry `dummy-registry`)</tspan>
</tspan> </tspan>
<tspan x="10px" y="82px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert --package my-package@0.1.1+my-package</tspan><tspan>`</tspan> <tspan x="10px" y="82px"><tspan class="fg-bright-green bold">note</tspan><tspan>: to see how you depend on my-package, run `</tspan><tspan class="fg-bright-cyan bold">cargo tree --invert my-package@0.1.1+my-package</tspan><tspan>`</tspan>
</tspan> </tspan>
<tspan x="10px" y="100px"> <tspan x="10px" y="100px">
</tspan> </tspan>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -1536,7 +1536,7 @@ fn report_behind() {
[UPDATING] breaking v0.1.0 -> v0.1.1 (available: v0.2.0) [UPDATING] breaking v0.1.0 -> v0.1.1 (available: v0.2.0)
[UNCHANGED] pre v1.0.0-alpha.0 (available: v1.0.0-alpha.1) [UNCHANGED] pre v1.0.0-alpha.0 (available: v1.0.0-alpha.1)
[UNCHANGED] two-ver v0.1.0 (available: v0.2.0) [UNCHANGED] two-ver v0.1.0 (available: v0.2.0)
[NOTE] to see how you depend on a package, run `cargo tree --invert --package <dep>@<ver>` [NOTE] to see how you depend on a package, run `cargo tree --invert <dep>@<ver>`
[WARNING] not updating lockfile due to dry run [WARNING] not updating lockfile due to dry run
"#]]) "#]])
@ -1561,7 +1561,7 @@ fn report_behind() {
[UNCHANGED] breaking v0.1.1 (available: v0.2.0) [UNCHANGED] breaking v0.1.1 (available: v0.2.0)
[UNCHANGED] pre v1.0.0-alpha.0 (available: v1.0.0-alpha.1) [UNCHANGED] pre v1.0.0-alpha.0 (available: v1.0.0-alpha.1)
[UNCHANGED] two-ver v0.1.0 (available: v0.2.0) [UNCHANGED] two-ver v0.1.0 (available: v0.2.0)
[NOTE] to see how you depend on a package, run `cargo tree --invert --package <dep>@<ver>` [NOTE] to see how you depend on a package, run `cargo tree --invert <dep>@<ver>`
[WARNING] not updating lockfile due to dry run [WARNING] not updating lockfile due to dry run
"#]]) "#]])