@@ -37,8 +37,7 @@ use crate::config::Options as RustdocOptions;
3737use crate :: html:: markdown:: { ErrorCodes , Ignore , LangString } ;
3838use crate :: lint:: init_lints;
3939
40- use self :: markdown:: MdDoctest ;
41- use self :: rust:: { HirCollector , RustDoctest } ;
40+ use self :: rust:: HirCollector ;
4241
4342/// Options that apply to all doctests in a crate or Markdown file (for `rustdoc foo.md`).
4443#[ derive( Clone , Default ) ]
@@ -194,7 +193,7 @@ pub(crate) fn run(
194193 tcx,
195194 ) ;
196195 let tests = hir_collector. collect_crate ( ) ;
197- tests. into_iter ( ) . for_each ( |t| collector. add_test ( ScrapedDoctest :: Rust ( t ) ) ) ;
196+ tests. into_iter ( ) . for_each ( |t| collector. add_test ( t ) ) ;
198197
199198 collector
200199 } ) ;
@@ -976,9 +975,12 @@ impl IndividualTestOptions {
976975}
977976
978977/// A doctest scraped from the code, ready to be turned into a runnable test.
979- enum ScrapedDoctest {
980- Rust ( RustDoctest ) ,
981- Markdown ( MdDoctest ) ,
978+ struct ScrapedDoctest {
979+ filename : FileName ,
980+ line : usize ,
981+ logical_path : Vec < String > ,
982+ langstr : LangString ,
983+ text : String ,
982984}
983985
984986pub ( crate ) trait DoctestVisitor {
@@ -1030,27 +1032,18 @@ impl CreateRunnableDoctests {
10301032 }
10311033
10321034 fn add_test ( & mut self , test : ScrapedDoctest ) {
1033- let ( filename, line, logical_path, langstr, text) = match test {
1034- ScrapedDoctest :: Rust ( RustDoctest { filename, line, logical_path, langstr, text } ) => {
1035- ( filename, line, logical_path, langstr, text)
1036- }
1037- ScrapedDoctest :: Markdown ( MdDoctest { filename, line, logical_path, langstr, text } ) => {
1038- ( filename, line, logical_path, langstr, text)
1039- }
1040- } ;
1041-
1042- let name = self . generate_name ( & filename, line, & logical_path) ;
1035+ let name = self . generate_name ( & test. filename , test. line , & test. logical_path ) ;
10431036 let crate_name = self . crate_name . clone ( ) ;
10441037 let opts = self . opts . clone ( ) ;
1045- let edition = langstr. edition . unwrap_or ( self . rustdoc_options . edition ) ;
1038+ let edition = test . langstr . edition . unwrap_or ( self . rustdoc_options . edition ) ;
10461039 let target_str = self . rustdoc_options . target . to_string ( ) ;
10471040 let unused_externs = self . unused_extern_reports . clone ( ) ;
1048- let no_run = langstr. no_run || self . rustdoc_options . no_run ;
1049- if !langstr. compile_fail {
1041+ let no_run = test . langstr . no_run || self . rustdoc_options . no_run ;
1042+ if !test . langstr . compile_fail {
10501043 self . compiling_test_count . fetch_add ( 1 , Ordering :: SeqCst ) ;
10511044 }
10521045
1053- let path = match & filename {
1046+ let path = match & test . filename {
10541047 FileName :: Real ( path) => {
10551048 if let Some ( local_path) = path. local_path ( ) {
10561049 local_path. to_path_buf ( )
@@ -1063,7 +1056,8 @@ impl CreateRunnableDoctests {
10631056 } ;
10641057
10651058 // For example `module/file.rs` would become `module_file_rs`
1066- let file = filename
1059+ let file = test
1060+ . filename
10671061 . prefer_local ( )
10681062 . to_string_lossy ( )
10691063 . chars ( )
@@ -1072,22 +1066,25 @@ impl CreateRunnableDoctests {
10721066 let test_id = format ! (
10731067 "{file}_{line}_{number}" ,
10741068 file = file,
1075- line = line,
1069+ line = test . line,
10761070 number = {
10771071 // Increases the current test number, if this file already
10781072 // exists or it creates a new entry with a test number of 0.
1079- self . visited_tests. entry( ( file. clone( ) , line) ) . and_modify( |v| * v += 1 ) . or_insert( 0 )
1073+ self . visited_tests
1074+ . entry( ( file. clone( ) , test. line) )
1075+ . and_modify( |v| * v += 1 )
1076+ . or_insert( 0 )
10801077 } ,
10811078 ) ;
10821079
10831080 let rustdoc_test_options =
10841081 IndividualTestOptions :: new ( & self . rustdoc_options , & self . arg_file , test_id) ;
10851082
1086- debug ! ( "creating test {name}: {text}" ) ;
1083+ debug ! ( "creating test {name}: {}" , test . text ) ;
10871084 self . tests . push ( test:: TestDescAndFn {
10881085 desc : test:: TestDesc {
10891086 name : test:: DynTestName ( name) ,
1090- ignore : match langstr. ignore {
1087+ ignore : match test . langstr . ignore {
10911088 Ignore :: All => true ,
10921089 Ignore :: None => false ,
10931090 Ignore :: Some ( ref ignores) => ignores. iter ( ) . any ( |s| target_str. contains ( s) ) ,
@@ -1100,22 +1097,20 @@ impl CreateRunnableDoctests {
11001097 end_col : 0 ,
11011098 // compiler failures are test failures
11021099 should_panic : test:: ShouldPanic :: No ,
1103- compile_fail : langstr. compile_fail ,
1100+ compile_fail : test . langstr . compile_fail ,
11041101 no_run,
11051102 test_type : test:: TestType :: DocTest ,
11061103 } ,
11071104 testfn : test:: DynTestFn ( Box :: new ( move || {
11081105 doctest_run_fn (
11091106 RunnableDoctest {
11101107 crate_name,
1111- line,
11121108 rustdoc_test_options,
1113- langstr,
11141109 no_run,
11151110 opts,
11161111 edition,
11171112 path,
1118- text ,
1113+ scraped_test : test ,
11191114 } ,
11201115 unused_externs,
11211116 )
@@ -1127,45 +1122,31 @@ impl CreateRunnableDoctests {
11271122/// A doctest that is ready to run.
11281123struct RunnableDoctest {
11291124 crate_name : String ,
1130- line : usize ,
11311125 rustdoc_test_options : IndividualTestOptions ,
1132- langstr : LangString ,
11331126 no_run : bool ,
11341127 opts : GlobalTestOptions ,
11351128 edition : Edition ,
11361129 path : PathBuf ,
1137- text : String ,
1130+ scraped_test : ScrapedDoctest ,
11381131}
11391132
11401133fn doctest_run_fn (
1141- test : RunnableDoctest ,
1134+ runnable_test : RunnableDoctest ,
11421135 unused_externs : Arc < Mutex < Vec < UnusedExterns > > > ,
11431136) -> Result < ( ) , String > {
1144- let RunnableDoctest {
1145- crate_name,
1146- line,
1147- rustdoc_test_options,
1148- langstr,
1149- no_run,
1150- opts,
1151- edition,
1152- path,
1153- text,
1154- } = test;
1155-
11561137 let report_unused_externs = |uext| {
11571138 unused_externs. lock ( ) . unwrap ( ) . push ( uext) ;
11581139 } ;
11591140 let res = run_test (
1160- & text,
1161- & crate_name,
1162- line,
1163- rustdoc_test_options,
1164- langstr,
1165- no_run,
1166- & opts,
1167- edition,
1168- path,
1141+ & runnable_test . scraped_test . text ,
1142+ & runnable_test . crate_name ,
1143+ runnable_test . scraped_test . line ,
1144+ runnable_test . rustdoc_test_options ,
1145+ runnable_test . scraped_test . langstr ,
1146+ runnable_test . no_run ,
1147+ & runnable_test . opts ,
1148+ runnable_test . edition ,
1149+ runnable_test . path ,
11691150 report_unused_externs,
11701151 ) ;
11711152
0 commit comments