@@ -16,7 +16,7 @@ use std::{fmt, panic, str};
1616
1717pub ( crate ) use make:: { BuildDocTestBuilder , DocTestBuilder } ;
1818pub ( crate ) use markdown:: test as test_markdown;
19- use rustc_data_structures:: fx:: { FxHashMap , FxHasher , FxIndexMap , FxIndexSet } ;
19+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxHasher , FxIndexMap , FxIndexSet } ;
2020use rustc_errors:: emitter:: HumanReadableErrorType ;
2121use rustc_errors:: { ColorConfig , DiagCtxtHandle } ;
2222use rustc_hir as hir;
@@ -689,6 +689,10 @@ fn run_test(
689689 "--extern=doctest_bundle_{edition}=" ,
690690 edition = doctest. edition
691691 ) ) ;
692+
693+ // Deduplicate passed -L directory paths, since usually all dependencies will be in the
694+ // same directory (e.g. target/debug/deps from Cargo).
695+ let mut seen_search_dirs = FxHashSet :: default ( ) ;
692696 for extern_str in & rustdoc_options. extern_strs {
693697 if let Some ( ( _cratename, path) ) = extern_str. split_once ( '=' ) {
694698 // Direct dependencies of the tests themselves are
@@ -698,7 +702,9 @@ fn run_test(
698702 . parent ( )
699703 . filter ( |x| x. components ( ) . count ( ) > 0 )
700704 . unwrap_or ( Path :: new ( "." ) ) ;
701- runner_compiler. arg ( "-L" ) . arg ( dir) ;
705+ if seen_search_dirs. insert ( dir) {
706+ runner_compiler. arg ( "-L" ) . arg ( dir) ;
707+ }
702708 }
703709 }
704710 let output_bundle_file = doctest
0 commit comments