@@ -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 } ) ;
@@ -977,9 +976,12 @@ impl IndividualTestOptions {
977976}
978977
979978/// A doctest scraped from the code, ready to be turned into a runnable test.
980- enum ScrapedDoctest {
981- Rust ( RustDoctest ) ,
982- Markdown ( MdDoctest ) ,
979+ struct ScrapedDoctest {
980+ filename : FileName ,
981+ line : usize ,
982+ logical_path : Vec < String > ,
983+ langstr : LangString ,
984+ text : String ,
983985}
984986
985987pub ( crate ) trait DoctestVisitor {
@@ -1031,27 +1033,18 @@ impl CreateRunnableDoctests {
10311033 }
10321034
10331035 fn add_test ( & mut self , test : ScrapedDoctest ) {
1034- let ( filename, line, logical_path, langstr, text) = match test {
1035- ScrapedDoctest :: Rust ( RustDoctest { filename, line, logical_path, langstr, text } ) => {
1036- ( filename, line, logical_path, langstr, text)
1037- }
1038- ScrapedDoctest :: Markdown ( MdDoctest { filename, line, logical_path, langstr, text } ) => {
1039- ( filename, line, logical_path, langstr, text)
1040- }
1041- } ;
1042-
1043- let name = self . generate_name ( & filename, line, & logical_path) ;
1036+ let name = self . generate_name ( & test. filename , test. line , & test. logical_path ) ;
10441037 let crate_name = self . crate_name . clone ( ) ;
10451038 let opts = self . opts . clone ( ) ;
1046- let edition = langstr. edition . unwrap_or ( self . rustdoc_options . edition ) ;
1039+ let edition = test . langstr . edition . unwrap_or ( self . rustdoc_options . edition ) ;
10471040 let target_str = self . rustdoc_options . target . to_string ( ) ;
10481041 let unused_externs = self . unused_extern_reports . clone ( ) ;
1049- let no_run = langstr. no_run || self . rustdoc_options . no_run ;
1050- if !langstr. compile_fail {
1042+ let no_run = test . langstr . no_run || self . rustdoc_options . no_run ;
1043+ if !test . langstr . compile_fail {
10511044 self . compiling_test_count . fetch_add ( 1 , Ordering :: SeqCst ) ;
10521045 }
10531046
1054- let path = match & filename {
1047+ let path = match & test . filename {
10551048 FileName :: Real ( path) => {
10561049 if let Some ( local_path) = path. local_path ( ) {
10571050 local_path. to_path_buf ( )
@@ -1064,7 +1057,8 @@ impl CreateRunnableDoctests {
10641057 } ;
10651058
10661059 // For example `module/file.rs` would become `module_file_rs`
1067- let file = filename
1060+ let file = test
1061+ . filename
10681062 . prefer_local ( )
10691063 . to_string_lossy ( )
10701064 . chars ( )
@@ -1073,22 +1067,25 @@ impl CreateRunnableDoctests {
10731067 let test_id = format ! (
10741068 "{file}_{line}_{number}" ,
10751069 file = file,
1076- line = line,
1070+ line = test . line,
10771071 number = {
10781072 // Increases the current test number, if this file already
10791073 // exists or it creates a new entry with a test number of 0.
1080- self . visited_tests. entry( ( file. clone( ) , line) ) . and_modify( |v| * v += 1 ) . or_insert( 0 )
1074+ self . visited_tests
1075+ . entry( ( file. clone( ) , test. line) )
1076+ . and_modify( |v| * v += 1 )
1077+ . or_insert( 0 )
10811078 } ,
10821079 ) ;
10831080
10841081 let rustdoc_test_options =
10851082 IndividualTestOptions :: new ( & self . rustdoc_options , & self . arg_file , test_id) ;
10861083
1087- debug ! ( "creating test {name}: {text}" ) ;
1084+ debug ! ( "creating test {name}: {}" , test . text ) ;
10881085 self . tests . push ( test:: TestDescAndFn {
10891086 desc : test:: TestDesc {
10901087 name : test:: DynTestName ( name) ,
1091- ignore : match langstr. ignore {
1088+ ignore : match test . langstr . ignore {
10921089 Ignore :: All => true ,
10931090 Ignore :: None => false ,
10941091 Ignore :: Some ( ref ignores) => ignores. iter ( ) . any ( |s| target_str. contains ( s) ) ,
@@ -1101,22 +1098,20 @@ impl CreateRunnableDoctests {
11011098 end_col : 0 ,
11021099 // compiler failures are test failures
11031100 should_panic : test:: ShouldPanic :: No ,
1104- compile_fail : langstr. compile_fail ,
1101+ compile_fail : test . langstr . compile_fail ,
11051102 no_run,
11061103 test_type : test:: TestType :: DocTest ,
11071104 } ,
11081105 testfn : test:: DynTestFn ( Box :: new ( move || {
11091106 doctest_run_fn (
11101107 RunnableDoctest {
11111108 crate_name,
1112- line,
11131109 rustdoc_test_options,
1114- langstr,
11151110 no_run,
11161111 opts,
11171112 edition,
11181113 path,
1119- text ,
1114+ scraped_test : test ,
11201115 } ,
11211116 unused_externs,
11221117 )
@@ -1128,45 +1123,31 @@ impl CreateRunnableDoctests {
11281123/// A doctest that is ready to run.
11291124struct RunnableDoctest {
11301125 crate_name : String ,
1131- line : usize ,
11321126 rustdoc_test_options : IndividualTestOptions ,
1133- langstr : LangString ,
11341127 no_run : bool ,
11351128 opts : GlobalTestOptions ,
11361129 edition : Edition ,
11371130 path : PathBuf ,
1138- text : String ,
1131+ scraped_test : ScrapedDoctest ,
11391132}
11401133
11411134fn doctest_run_fn (
1142- test : RunnableDoctest ,
1135+ runnable_test : RunnableDoctest ,
11431136 unused_externs : Arc < Mutex < Vec < UnusedExterns > > > ,
11441137) -> Result < ( ) , String > {
1145- let RunnableDoctest {
1146- crate_name,
1147- line,
1148- rustdoc_test_options,
1149- langstr,
1150- no_run,
1151- opts,
1152- edition,
1153- path,
1154- text,
1155- } = test;
1156-
11571138 let report_unused_externs = |uext| {
11581139 unused_externs. lock ( ) . unwrap ( ) . push ( uext) ;
11591140 } ;
11601141 let res = run_test (
1161- & text,
1162- & crate_name,
1163- line,
1164- rustdoc_test_options,
1165- langstr,
1166- no_run,
1167- & opts,
1168- edition,
1169- path,
1142+ & runnable_test . scraped_test . text ,
1143+ & runnable_test . crate_name ,
1144+ runnable_test . scraped_test . line ,
1145+ runnable_test . rustdoc_test_options ,
1146+ runnable_test . scraped_test . langstr ,
1147+ runnable_test . no_run ,
1148+ & runnable_test . opts ,
1149+ runnable_test . edition ,
1150+ runnable_test . path ,
11701151 report_unused_externs,
11711152 ) ;
11721153
0 commit comments