@@ -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;
@@ -281,7 +282,7 @@ pub(crate) fn run_tests(
281
282
rustdoc_options : & Arc < RustdocOptions > ,
282
283
unused_extern_reports : & Arc < Mutex < Vec < UnusedExterns > > > ,
283
284
mut standalone_tests : Vec < test:: TestDescAndFn > ,
284
- mergeable_tests : FxIndexMap < Edition , Vec < ( DocTestBuilder , ScrapedDocTest ) > > ,
285
+ mergeable_tests : FxIndexMap < MergeableTestKey , Vec < ( DocTestBuilder , ScrapedDocTest ) > > ,
285
286
// We pass this argument so we can drop it manually before using `exit`.
286
287
mut temp_dir : Option < TempDir > ,
287
288
) {
@@ -296,7 +297,7 @@ pub(crate) fn run_tests(
296
297
let mut ran_edition_tests = 0 ;
297
298
let target_str = rustdoc_options. target . to_string ( ) ;
298
299
299
- for ( edition, mut doctests) in mergeable_tests {
300
+ for ( MergeableTestKey { edition, global_crate_attrs_hash } , mut doctests) in mergeable_tests {
300
301
if doctests. is_empty ( ) {
301
302
continue ;
302
303
}
@@ -306,8 +307,8 @@ pub(crate) fn run_tests(
306
307
307
308
let rustdoc_test_options = IndividualTestOptions :: new (
308
309
rustdoc_options,
309
- & Some ( format ! ( "merged_doctest_{edition}" ) ) ,
310
- PathBuf :: from ( format ! ( "doctest_{edition}.rs" ) ) ,
310
+ & Some ( format ! ( "merged_doctest_{edition}_{global_crate_attrs_hash} " ) ) ,
311
+ PathBuf :: from ( format ! ( "doctest_{edition}_{global_crate_attrs_hash} .rs" ) ) ,
311
312
) ;
312
313
313
314
for ( doctest, scraped_test) in & doctests {
@@ -885,9 +886,15 @@ pub(crate) trait DocTestVisitor {
885
886
fn visit_header ( & mut self , _name : & str , _level : u32 ) { }
886
887
}
887
888
889
+ #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
890
+ pub ( crate ) struct MergeableTestKey {
891
+ edition : Edition ,
892
+ global_crate_attrs_hash : u64 ,
893
+ }
894
+
888
895
struct CreateRunnableDocTests {
889
896
standalone_tests : Vec < test:: TestDescAndFn > ,
890
- mergeable_tests : FxIndexMap < Edition , Vec < ( DocTestBuilder , ScrapedDocTest ) > > ,
897
+ mergeable_tests : FxIndexMap < MergeableTestKey , Vec < ( DocTestBuilder , ScrapedDocTest ) > > ,
891
898
892
899
rustdoc_options : Arc < RustdocOptions > ,
893
900
opts : GlobalTestOptions ,
@@ -955,7 +962,17 @@ impl CreateRunnableDocTests {
955
962
let test_desc = self . generate_test_desc_and_fn ( doctest, scraped_test) ;
956
963
self . standalone_tests . push ( test_desc) ;
957
964
} else {
958
- self . mergeable_tests . entry ( edition) . or_default ( ) . push ( ( doctest, scraped_test) ) ;
965
+ self . mergeable_tests
966
+ . entry ( MergeableTestKey {
967
+ edition,
968
+ global_crate_attrs_hash : {
969
+ let mut hasher = FxHasher :: default ( ) ;
970
+ scraped_test. global_crate_attrs . hash ( & mut hasher) ;
971
+ hasher. finish ( )
972
+ } ,
973
+ } )
974
+ . or_default ( )
975
+ . push ( ( doctest, scraped_test) ) ;
959
976
}
960
977
}
961
978
0 commit comments