@@ -408,7 +408,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
408408 tests. add_test ( text. to_owned ( ) ,
409409 block_info. should_panic , block_info. no_run ,
410410 block_info. ignore , block_info. test_harness ,
411- block_info. compile_fail ) ;
411+ block_info. compile_fail , block_info . error_codes ) ;
412412 }
413413 }
414414
@@ -454,6 +454,7 @@ struct LangString {
454454 rust : bool ,
455455 test_harness : bool ,
456456 compile_fail : bool ,
457+ error_codes : Vec < String > ,
457458}
458459
459460impl LangString {
@@ -465,16 +466,22 @@ impl LangString {
465466 rust : true , // NB This used to be `notrust = false`
466467 test_harness : false ,
467468 compile_fail : false ,
469+ error_codes : Vec :: new ( ) ,
468470 }
469471 }
470472
471473 fn parse ( string : & str ) -> LangString {
472474 let mut seen_rust_tags = false ;
473475 let mut seen_other_tags = false ;
474476 let mut data = LangString :: all_false ( ) ;
475- let allow_compile_fail = match get_unstable_features_setting ( ) {
476- UnstableFeatures :: Allow | UnstableFeatures :: Cheat => true ,
477- _ => false ,
477+ let mut allow_compile_fail = false ;
478+ let mut allow_error_code_check = false ;
479+ match get_unstable_features_setting ( ) {
480+ UnstableFeatures :: Allow | UnstableFeatures :: Cheat => {
481+ allow_compile_fail = true ;
482+ allow_error_code_check = true ;
483+ }
484+ _ => { } ,
478485 } ;
479486
480487 let tokens = string. split ( |c : char |
@@ -493,7 +500,15 @@ impl LangString {
493500 data. compile_fail = true ;
494501 seen_rust_tags = true ;
495502 data. no_run = true ;
496- } ,
503+ }
504+ x if allow_error_code_check && x. starts_with ( "E" ) && x. len ( ) == 5 => {
505+ if let Ok ( _) = x[ 1 ..] . parse :: < u32 > ( ) {
506+ data. error_codes . push ( x. to_owned ( ) ) ;
507+ seen_rust_tags = true ;
508+ } else {
509+ seen_other_tags = true ;
510+ }
511+ }
497512 _ => { seen_other_tags = true }
498513 }
499514 }
@@ -577,30 +592,34 @@ mod tests {
577592 fn test_lang_string_parse ( ) {
578593 fn t ( s : & str ,
579594 should_panic : bool , no_run : bool , ignore : bool , rust : bool , test_harness : bool ,
580- compile_fail : bool ) {
595+ compile_fail : bool , error_codes : Vec < String > ) {
581596 assert_eq ! ( LangString :: parse( s) , LangString {
582597 should_panic: should_panic,
583598 no_run: no_run,
584599 ignore: ignore,
585600 rust: rust,
586601 test_harness: test_harness,
587602 compile_fail: compile_fail,
603+ error_codes: error_codes,
588604 } )
589605 }
590606
591607 // marker | should_panic| no_run| ignore| rust | test_harness| compile_fail
592- t ( "" , false , false , false , true , false , false ) ;
593- t ( "rust" , false , false , false , true , false , false ) ;
594- t ( "sh" , false , false , false , false , false , false ) ;
595- t ( "ignore" , false , false , true , true , false , false ) ;
596- t ( "should_panic" , true , false , false , true , false , false ) ;
597- t ( "no_run" , false , true , false , true , false , false ) ;
598- t ( "test_harness" , false , false , false , true , true , false ) ;
599- t ( "compile_fail" , false , true , false , true , false , true ) ;
600- t ( "{.no_run .example}" , false , true , false , true , false , false ) ;
601- t ( "{.sh .should_panic}" , true , false , false , true , false , false ) ;
602- t ( "{.example .rust}" , false , false , false , true , false , false ) ;
603- t ( "{.test_harness .rust}" , false , false , false , true , true , false ) ;
608+ // | error_codes
609+ t ( "" , false , false , false , true , false , false , Vec :: new ( ) ) ;
610+ t ( "rust" , false , false , false , true , false , false , Vec :: new ( ) ) ;
611+ t ( "sh" , false , false , false , false , false , false , Vec :: new ( ) ) ;
612+ t ( "ignore" , false , false , true , true , false , false , Vec :: new ( ) ) ;
613+ t ( "should_panic" , true , false , false , true , false , false , Vec :: new ( ) ) ;
614+ t ( "no_run" , false , true , false , true , false , false , Vec :: new ( ) ) ;
615+ t ( "test_harness" , false , false , false , true , true , false , Vec :: new ( ) ) ;
616+ t ( "compile_fail" , false , true , false , true , false , true , Vec :: new ( ) ) ;
617+ t ( "E0450" , false , false , false , true , false , false ,
618+ vec ! ( "E0450" . to_owned( ) ) ) ;
619+ t ( "{.no_run .example}" , false , true , false , true , false , false , Vec :: new ( ) ) ;
620+ t ( "{.sh .should_panic}" , true , false , false , true , false , false , Vec :: new ( ) ) ;
621+ t ( "{.example .rust}" , false , false , false , true , false , false , Vec :: new ( ) ) ;
622+ t ( "{.test_harness .rust}" , false , false , false , true , true , false , Vec :: new ( ) ) ;
604623 }
605624
606625 #[ test]
0 commit comments