@@ -5,6 +5,7 @@ mod runner;
5
5
mod rust;
6
6
7
7
use std:: fs:: File ;
8
+ use std:: hash:: { Hash , Hasher } ;
8
9
use std:: io:: { self , Write } ;
9
10
use std:: path:: { Path , PathBuf } ;
10
11
use std:: process:: { self , Command , Stdio } ;
@@ -14,7 +15,7 @@ use std::{panic, str};
14
15
15
16
pub ( crate ) use make:: DocTestBuilder ;
16
17
pub ( crate ) use markdown:: test as test_markdown;
17
- use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap , FxIndexSet } ;
18
+ use rustc_data_structures:: fx:: { FxHashMap , FxHasher , FxIndexMap , FxIndexSet } ;
18
19
use rustc_errors:: emitter:: HumanReadableErrorType ;
19
20
use rustc_errors:: { ColorConfig , DiagCtxtHandle } ;
20
21
use rustc_hir as hir;
@@ -323,7 +324,7 @@ pub(crate) fn run_tests(
323
324
rustdoc_options : & Arc < RustdocOptions > ,
324
325
unused_extern_reports : & Arc < Mutex < Vec < UnusedExterns > > > ,
325
326
mut standalone_tests : Vec < test:: TestDescAndFn > ,
326
- mergeable_tests : FxIndexMap < Edition , Vec < ( DocTestBuilder , ScrapedDocTest ) > > ,
327
+ mergeable_tests : FxIndexMap < MergeableTestKey , Vec < ( DocTestBuilder , ScrapedDocTest ) > > ,
327
328
// We pass this argument so we can drop it manually before using `exit`.
328
329
mut temp_dir : Option < TempDir > ,
329
330
) {
@@ -338,7 +339,7 @@ pub(crate) fn run_tests(
338
339
let mut ran_edition_tests = 0 ;
339
340
let target_str = rustdoc_options. target . to_string ( ) ;
340
341
341
- for ( edition, mut doctests) in mergeable_tests {
342
+ for ( MergeableTestKey { edition, global_crate_attrs_hash } , mut doctests) in mergeable_tests {
342
343
if doctests. is_empty ( ) {
343
344
continue ;
344
345
}
@@ -348,8 +349,8 @@ pub(crate) fn run_tests(
348
349
349
350
let rustdoc_test_options = IndividualTestOptions :: new (
350
351
rustdoc_options,
351
- & Some ( format ! ( "merged_doctest_{edition}" ) ) ,
352
- PathBuf :: from ( format ! ( "doctest_{edition}.rs" ) ) ,
352
+ & Some ( format ! ( "merged_doctest_{edition}_{global_crate_attrs_hash} " ) ) ,
353
+ PathBuf :: from ( format ! ( "doctest_{edition}_{global_crate_attrs_hash} .rs" ) ) ,
353
354
) ;
354
355
355
356
for ( doctest, scraped_test) in & doctests {
@@ -927,9 +928,15 @@ pub(crate) trait DocTestVisitor {
927
928
fn visit_header ( & mut self , _name : & str , _level : u32 ) { }
928
929
}
929
930
931
+ #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
932
+ pub ( crate ) struct MergeableTestKey {
933
+ edition : Edition ,
934
+ global_crate_attrs_hash : u64 ,
935
+ }
936
+
930
937
struct CreateRunnableDocTests {
931
938
standalone_tests : Vec < test:: TestDescAndFn > ,
932
- mergeable_tests : FxIndexMap < Edition , Vec < ( DocTestBuilder , ScrapedDocTest ) > > ,
939
+ mergeable_tests : FxIndexMap < MergeableTestKey , Vec < ( DocTestBuilder , ScrapedDocTest ) > > ,
933
940
934
941
rustdoc_options : Arc < RustdocOptions > ,
935
942
opts : GlobalTestOptions ,
@@ -997,7 +1004,17 @@ impl CreateRunnableDocTests {
997
1004
let test_desc = self . generate_test_desc_and_fn ( doctest, scraped_test) ;
998
1005
self . standalone_tests . push ( test_desc) ;
999
1006
} else {
1000
- self . mergeable_tests . entry ( edition) . or_default ( ) . push ( ( doctest, scraped_test) ) ;
1007
+ self . mergeable_tests
1008
+ . entry ( MergeableTestKey {
1009
+ edition,
1010
+ global_crate_attrs_hash : {
1011
+ let mut hasher = FxHasher :: default ( ) ;
1012
+ scraped_test. global_crate_attrs . hash ( & mut hasher) ;
1013
+ hasher. finish ( )
1014
+ } ,
1015
+ } )
1016
+ . or_default ( )
1017
+ . push ( ( doctest, scraped_test) ) ;
1001
1018
}
1002
1019
}
1003
1020
0 commit comments