File tree Expand file tree Collapse file tree 3 files changed +55
-20
lines changed Expand file tree Collapse file tree 3 files changed +55
-20
lines changed Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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,
Original file line number Diff line number Diff line change @@ -1085,6 +1085,57 @@ fn duplicates_with_target() {
10851085 p. cargo ( "tree -d --target=all" ) . with_stdout ( "" ) . run ( ) ;
10861086}
10871087
1088+ #[ cargo_test]
1089+ fn duplicates_with_proc_macro ( ) {
1090+ Package :: new ( "cat" , "1.0.0" ) . publish ( ) ;
1091+ Package :: new ( "cat" , "2.0.0" ) . publish ( ) ;
1092+ Package :: new ( "dep" , "1.0.0" )
1093+ . proc_macro ( true )
1094+ . dep ( "cat" , "1.0" )
1095+ . publish ( ) ;
1096+ let p = project ( )
1097+ . file (
1098+ "Cargo.toml" ,
1099+ r#"
1100+ [package]
1101+ name = "foo"
1102+ version = "0.1.0"
1103+
1104+ [dependencies]
1105+ dep = "1.0"
1106+ cat = "2.0"
1107+ "# ,
1108+ )
1109+ . file ( "src/lib.rs" , "" )
1110+ . build ( ) ;
1111+
1112+ p. cargo ( "tree" )
1113+ . with_stdout (
1114+ "\
1115+ foo v0.1.0 ([..]/foo)
1116+ ├── cat v2.0.0
1117+ └── dep v1.0.0 (proc-macro)
1118+ └── cat v1.0.0
1119+ " ,
1120+ )
1121+ . run ( ) ;
1122+
1123+ p. cargo ( "tree -d" )
1124+ . with_stdout (
1125+ "\
1126+ cat v1.0.0
1127+ └── dep v1.0.0 (proc-macro)
1128+ └── foo v0.1.0 ([..]/foo)
1129+
1130+ cat v2.0.0
1131+ └── foo v0.1.0 ([..]/foo)
1132+ " ,
1133+ )
1134+ . run ( ) ;
1135+
1136+ p. cargo ( "tree -d -e no-proc-macro" ) . with_stdout ( "" ) . run ( ) ;
1137+ }
1138+
10881139#[ cargo_test]
10891140fn charset ( ) {
10901141 let p = make_simple_proj ( ) ;
@@ -1540,8 +1591,6 @@ somedep v1.0.0
15401591 "\
15411592 somedep v1.0.0
15421593└── foo v0.1.0 ([..]/foo)
1543-
1544- somedep v1.0.0
15451594" ,
15461595 )
15471596 . run ( ) ;
You can’t perform that action at this time.
0 commit comments