Skip to content

Commit a0576d1

Browse files
committed
cargo-tree: Handle -e no-proc-macro when building the graph
This is closer to how the edge-based filters work ([no-]build etc.), and results in a more useful behavior when combined with -i or -d.
1 parent 747a592 commit a0576d1

File tree

3 files changed

+5
-28
lines changed

3 files changed

+5
-28
lines changed

src/cargo/ops/tree/graph.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ fn add_pkg(
362362
if !opts.edge_kinds.contains(&EdgeKind::Dep(dep.kind())) {
363363
return false;
364364
}
365+
// Filter out proc-macrcos if requested.
366+
if opts.no_proc_macro && graph.package_for_id(dep_id).proc_macro() {
367+
return false;
368+
}
365369
if dep.is_optional() {
366370
// If the new feature resolver does not enable this
367371
// optional dep, then don't use it.

src/cargo/ops/tree/mod.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ fn print(
267267
opts.prefix,
268268
opts.no_dedupe,
269269
opts.max_display_depth,
270-
opts.no_proc_macro,
271270
&mut visited_deps,
272271
&mut levels_continue,
273272
&mut print_stack,
@@ -288,7 +287,6 @@ fn print_node<'a>(
288287
prefix: Prefix,
289288
no_dedupe: bool,
290289
max_display_depth: u32,
291-
no_proc_macro: bool,
292290
visited_deps: &mut HashSet<usize>,
293291
levels_continue: &mut Vec<bool>,
294292
print_stack: &mut Vec<usize>,
@@ -348,7 +346,6 @@ fn print_node<'a>(
348346
prefix,
349347
no_dedupe,
350348
max_display_depth,
351-
no_proc_macro,
352349
visited_deps,
353350
levels_continue,
354351
print_stack,
@@ -369,7 +366,6 @@ fn print_dependencies<'a>(
369366
prefix: Prefix,
370367
no_dedupe: bool,
371368
max_display_depth: u32,
372-
no_proc_macro: bool,
373369
visited_deps: &mut HashSet<usize>,
374370
levels_continue: &mut Vec<bool>,
375371
print_stack: &mut Vec<usize>,
@@ -405,19 +401,6 @@ fn print_dependencies<'a>(
405401

406402
let mut it = deps
407403
.iter()
408-
.filter(|dep| {
409-
// Filter out proc-macro dependencies.
410-
if no_proc_macro {
411-
match graph.node(**dep) {
412-
&Node::Package { package_id, .. } => {
413-
!graph.package_for_id(package_id).proc_macro()
414-
}
415-
_ => true,
416-
}
417-
} else {
418-
true
419-
}
420-
})
421404
.filter(|dep| {
422405
// Filter out packages to prune.
423406
match graph.node(**dep) {
@@ -441,7 +424,6 @@ fn print_dependencies<'a>(
441424
prefix,
442425
no_dedupe,
443426
max_display_depth,
444-
no_proc_macro,
445427
visited_deps,
446428
levels_continue,
447429
print_stack,

tests/testsuite/tree.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,14 +1134,7 @@ dupe-dep v2.0.0
11341134
.run();
11351135

11361136
p.cargo("tree --duplicates --edges no-proc-macro")
1137-
.with_stdout(
1138-
"\
1139-
dupe-dep v1.0.0
1140-
1141-
dupe-dep v2.0.0
1142-
└── foo v0.1.0 ([..]/foo)
1143-
",
1144-
)
1137+
.with_stdout("")
11451138
.run();
11461139
}
11471140

@@ -1600,8 +1593,6 @@ somedep v1.0.0
16001593
"\
16011594
somedep v1.0.0
16021595
└── foo v0.1.0 ([..]/foo)
1603-
1604-
somedep v1.0.0
16051596
",
16061597
)
16071598
.run();

0 commit comments

Comments
 (0)