8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ use std:: collections:: HashMap ;
11
12
use std:: env;
12
13
use std:: ffi:: OsString ;
13
14
use std:: io:: prelude:: * ;
@@ -381,7 +382,7 @@ fn partition_source(s: &str) -> (String, String) {
381
382
pub struct Collector {
382
383
pub tests : Vec < testing:: TestDescAndFn > ,
383
384
// to be removed when hoedown will be definitely gone
384
- pub old_tests : Vec < String > ,
385
+ pub old_tests : HashMap < String , Vec < String > > ,
385
386
names : Vec < String > ,
386
387
cfgs : Vec < String > ,
387
388
libs : SearchPaths ,
@@ -403,7 +404,7 @@ impl Collector {
403
404
codemap : Option < Rc < CodeMap > > , filename : Option < String > ) -> Collector {
404
405
Collector {
405
406
tests : Vec :: new ( ) ,
406
- old_tests : Vec :: new ( ) ,
407
+ old_tests : HashMap :: new ( ) ,
407
408
names : Vec :: new ( ) ,
408
409
cfgs : cfgs,
409
410
libs : libs,
@@ -432,17 +433,39 @@ impl Collector {
432
433
}
433
434
}
434
435
435
- pub fn add_old_test ( & mut self , line : usize , filename : String ) {
436
- let name = self . generate_name ( line, & filename) ;
437
- self . old_tests . push ( name) ;
436
+ // to be removed once hoedown is gone
437
+ fn generate_name_beginning ( & self , filename : & str ) -> String {
438
+ if self . use_headers {
439
+ if let Some ( ref header) = self . current_header {
440
+ format ! ( "{} - {} (line" , filename, header)
441
+ } else {
442
+ format ! ( "{} - (line" , filename)
443
+ }
444
+ } else {
445
+ format ! ( "{} - {} (line" , filename, self . names. join( "::" ) )
446
+ }
447
+ }
448
+
449
+ pub fn add_old_test ( & mut self , test : String , filename : String ) {
450
+ let name_beg = self . generate_name_beginning ( & filename) ;
451
+ let entry = self . old_tests . entry ( name_beg)
452
+ . or_insert ( Vec :: new ( ) ) ;
453
+ entry. push ( test. trim ( ) . to_owned ( ) ) ;
438
454
}
439
455
440
456
pub fn add_test ( & mut self , test : String ,
441
457
should_panic : bool , no_run : bool , should_ignore : bool ,
442
458
as_test_harness : bool , compile_fail : bool , error_codes : Vec < String > ,
443
459
line : usize , filename : String ) {
444
460
let name = self . generate_name ( line, & filename) ;
445
- if self . old_tests . iter ( ) . find ( |& x| x == & name) . is_none ( ) {
461
+ let name_beg = self . generate_name_beginning ( & filename) ;
462
+ let mut found = false ;
463
+ // to be removed when hoedown is removed
464
+ let test = test. trim ( ) . to_owned ( ) ;
465
+ if let Some ( entry) = self . old_tests . get_mut ( & name_beg) {
466
+ found = entry. remove_item ( & test) . is_some ( ) ;
467
+ }
468
+ if !found {
446
469
let _ = writeln ! ( & mut io:: stderr( ) ,
447
470
"WARNING: {} Code block is not currently run as a test, but will in \
448
471
future versions of rustdoc. Please ensure this code block is a \
0 commit comments