@@ -365,7 +365,8 @@ fn run_test(
365365 test : & str ,
366366 crate_name : & str ,
367367 line : usize ,
368- rustdoc_options : IndividualTestOptions ,
368+ rustdoc_options : & RustdocOptions ,
369+ test_options : IndividualTestOptions ,
369370 mut lang_string : LangString ,
370371 no_run : bool ,
371372 opts : & GlobalTestOptions ,
@@ -379,20 +380,20 @@ fn run_test(
379380 lang_string. test_harness ,
380381 opts,
381382 edition,
382- Some ( & rustdoc_options . test_id ) ,
383+ Some ( & test_options . test_id ) ,
383384 ) ;
384385
385386 // Make sure we emit well-formed executable names for our target.
386387 let rust_out = add_exe_suffix ( "rust_out" . to_owned ( ) , & rustdoc_options. target ) ;
387- let output_file = rustdoc_options . outdir . path ( ) . join ( rust_out) ;
388+ let output_file = test_options . outdir . path ( ) . join ( rust_out) ;
388389
389390 let rustc_binary = rustdoc_options
390391 . test_builder
391392 . as_deref ( )
392393 . unwrap_or_else ( || rustc_interface:: util:: rustc_path ( ) . expect ( "found rustc" ) ) ;
393394 let mut compiler = wrapped_rustc_command ( & rustdoc_options. test_builder_wrappers , rustc_binary) ;
394395
395- compiler. arg ( & format ! ( "@{}" , rustdoc_options . arg_file. display( ) ) ) ;
396+ compiler. arg ( & format ! ( "@{}" , test_options . arg_file. display( ) ) ) ;
396397
397398 if let Some ( sysroot) = & rustdoc_options. maybe_sysroot {
398399 compiler. arg ( format ! ( "--sysroot={}" , sysroot. display( ) ) ) ;
@@ -405,20 +406,22 @@ fn run_test(
405406 if lang_string. test_harness {
406407 compiler. arg ( "--test" ) ;
407408 }
408- if rustdoc_options. is_json_unused_externs_enabled && !lang_string. compile_fail {
409+ if rustdoc_options. json_unused_externs . is_enabled ( ) && !lang_string. compile_fail {
409410 compiler. arg ( "--error-format=json" ) ;
410411 compiler. arg ( "--json" ) . arg ( "unused-externs" ) ;
411412 compiler. arg ( "-W" ) . arg ( "unused_crate_dependencies" ) ;
412413 compiler. arg ( "-Z" ) . arg ( "unstable-options" ) ;
413414 }
414415
415- if no_run && !lang_string. compile_fail && rustdoc_options. should_persist_doctests {
416+ if no_run && !lang_string. compile_fail && rustdoc_options. persist_doctests . is_none ( ) {
417+ // FIXME: why does this code check if it *shouldn't* persist doctests
418+ // -- shouldn't it be the negation?
416419 compiler. arg ( "--emit=metadata" ) ;
417420 }
418- compiler. arg ( "--target" ) . arg ( match rustdoc_options. target {
421+ compiler. arg ( "--target" ) . arg ( match & rustdoc_options. target {
419422 TargetTriple :: TargetTriple ( s) => s,
420423 TargetTriple :: TargetJson { path_for_rustdoc, .. } => {
421- path_for_rustdoc. to_str ( ) . expect ( "target path must be valid unicode" ) . to_string ( )
424+ path_for_rustdoc. to_str ( ) . expect ( "target path must be valid unicode" )
422425 }
423426 } ) ;
424427 if let ErrorOutputType :: HumanReadable ( kind) = rustdoc_options. error_format {
@@ -511,15 +514,15 @@ fn run_test(
511514 let mut cmd;
512515
513516 let output_file = make_maybe_absolute_path ( output_file) ;
514- if let Some ( tool) = rustdoc_options. runtool {
517+ if let Some ( tool) = & rustdoc_options. runtool {
515518 let tool = make_maybe_absolute_path ( tool. into ( ) ) ;
516519 cmd = Command :: new ( tool) ;
517- cmd. args ( rustdoc_options. runtool_args ) ;
520+ cmd. args ( & rustdoc_options. runtool_args ) ;
518521 cmd. arg ( output_file) ;
519522 } else {
520523 cmd = Command :: new ( output_file) ;
521524 }
522- if let Some ( run_directory) = rustdoc_options. test_run_directory {
525+ if let Some ( run_directory) = & rustdoc_options. test_run_directory {
523526 cmd. current_dir ( run_directory) ;
524527 }
525528
@@ -924,20 +927,9 @@ fn partition_source(s: &str, edition: Edition) -> (String, String, String) {
924927}
925928
926929pub ( crate ) struct IndividualTestOptions {
927- test_builder : Option < PathBuf > ,
928- test_builder_wrappers : Vec < PathBuf > ,
929- is_json_unused_externs_enabled : bool ,
930- should_persist_doctests : bool ,
931- error_format : ErrorOutputType ,
932- test_run_directory : Option < PathBuf > ,
933- nocapture : bool ,
934930 arg_file : PathBuf ,
935931 outdir : DirState ,
936- runtool : Option < String > ,
937- runtool_args : Vec < String > ,
938- target : TargetTriple ,
939932 test_id : String ,
940- maybe_sysroot : Option < PathBuf > ,
941933}
942934
943935impl IndividualTestOptions {
@@ -956,22 +948,7 @@ impl IndividualTestOptions {
956948 DirState :: Temp ( get_doctest_dir ( ) . expect ( "rustdoc needs a tempdir" ) )
957949 } ;
958950
959- Self {
960- test_builder : options. test_builder . clone ( ) ,
961- test_builder_wrappers : options. test_builder_wrappers . clone ( ) ,
962- is_json_unused_externs_enabled : options. json_unused_externs . is_enabled ( ) ,
963- should_persist_doctests : options. persist_doctests . is_none ( ) ,
964- error_format : options. error_format ,
965- test_run_directory : options. test_run_directory . clone ( ) ,
966- nocapture : options. nocapture ,
967- arg_file : arg_file. into ( ) ,
968- outdir,
969- runtool : options. runtool . clone ( ) ,
970- runtool_args : options. runtool_args . clone ( ) ,
971- target : options. target . clone ( ) ,
972- test_id,
973- maybe_sysroot : options. maybe_sysroot . clone ( ) ,
974- }
951+ Self { arg_file : arg_file. into ( ) , outdir, test_id }
975952 }
976953}
977954
@@ -995,7 +972,7 @@ pub(crate) trait DoctestVisitor {
995972pub ( crate ) struct CreateRunnableDoctests {
996973 pub ( crate ) tests : Vec < test:: TestDescAndFn > ,
997974
998- rustdoc_options : RustdocOptions ,
975+ rustdoc_options : Arc < RustdocOptions > ,
999976 crate_name : String ,
1000977 opts : GlobalTestOptions ,
1001978 visited_tests : FxHashMap < ( String , usize ) , usize > ,
@@ -1013,7 +990,7 @@ impl CreateRunnableDoctests {
1013990 ) -> CreateRunnableDoctests {
1014991 CreateRunnableDoctests {
1015992 tests : Vec :: new ( ) ,
1016- rustdoc_options,
993+ rustdoc_options : Arc :: new ( rustdoc_options ) ,
1017994 crate_name,
1018995 opts,
1019996 visited_tests : FxHashMap :: default ( ) ,
@@ -1078,6 +1055,7 @@ impl CreateRunnableDoctests {
10781055 } ,
10791056 ) ;
10801057
1058+ let rustdoc_options = self . rustdoc_options . clone ( ) ;
10811059 let rustdoc_test_options =
10821060 IndividualTestOptions :: new ( & self . rustdoc_options , & self . arg_file , test_id) ;
10831061
@@ -1113,6 +1091,7 @@ impl CreateRunnableDoctests {
11131091 path,
11141092 scraped_test : test,
11151093 } ,
1094+ rustdoc_options,
11161095 unused_externs,
11171096 )
11181097 } ) ) ,
@@ -1133,6 +1112,7 @@ struct RunnableDoctest {
11331112
11341113fn doctest_run_fn (
11351114 runnable_test : RunnableDoctest ,
1115+ rustdoc_options : Arc < RustdocOptions > ,
11361116 unused_externs : Arc < Mutex < Vec < UnusedExterns > > > ,
11371117) -> Result < ( ) , String > {
11381118 let report_unused_externs = |uext| {
@@ -1142,6 +1122,7 @@ fn doctest_run_fn(
11421122 & runnable_test. scraped_test . text ,
11431123 & runnable_test. crate_name ,
11441124 runnable_test. scraped_test . line ,
1125+ & rustdoc_options,
11451126 runnable_test. rustdoc_test_options ,
11461127 runnable_test. scraped_test . langstr ,
11471128 runnable_test. no_run ,
0 commit comments