@@ -459,12 +459,7 @@ fn run_test(
459
459
let stdin = child. stdin . as_mut ( ) . expect ( "Failed to open stdin" ) ;
460
460
stdin. write_all ( test. as_bytes ( ) ) . expect ( "could write out test sources" ) ;
461
461
}
462
- let output = if !is_multiple_tests {
463
- let status = child. wait ( ) . expect ( "Failed to wait" ) ;
464
- process:: Output { status, stdout : Vec :: new ( ) , stderr : Vec :: new ( ) }
465
- } else {
466
- child. wait_with_output ( ) . expect ( "Failed to read stdout" )
467
- } ;
462
+ let output = child. wait_with_output ( ) . expect ( "Failed to read stdout" ) ;
468
463
469
464
struct Bomb < ' a > ( & ' a str ) ;
470
465
impl Drop for Bomb < ' _ > {
@@ -603,6 +598,11 @@ impl DocTest {
603
598
// If `test_id` is `None`, it means we're generating code for a code example "run" link.
604
599
test_id : Option < & str > ,
605
600
) -> ( String , usize ) {
601
+ if self . failed_ast {
602
+ // If the AST failed to compile, no need to go generate a complete doctest, the error
603
+ // will be better this way.
604
+ return ( self . everything_else . clone ( ) , 0 ) ;
605
+ }
606
606
let mut line_offset = 0 ;
607
607
let mut prog = String :: with_capacity (
608
608
self . test_code . len ( ) + self . crate_attrs . len ( ) + self . crates . len ( ) ,
@@ -942,11 +942,10 @@ pub(crate) fn make_test(
942
942
Ok ( p) => p,
943
943
Err ( errs) => {
944
944
errs. into_iter ( ) . for_each ( |err| err. cancel ( ) ) ;
945
- return ( found_main, found_extern_crate, found_macro, true ) ;
945
+ return ( found_main, found_extern_crate, found_macro) ;
946
946
}
947
947
} ;
948
948
949
- let mut has_errors = false ;
950
949
loop {
951
950
match parser. parse_item ( ForceCollect :: No ) {
952
951
Ok ( Some ( item) ) => {
@@ -977,7 +976,6 @@ pub(crate) fn make_test(
977
976
Ok ( None ) => break ,
978
977
Err ( e) => {
979
978
e. cancel ( ) ;
980
- has_errors = true ;
981
979
break ;
982
980
}
983
981
}
@@ -987,14 +985,13 @@ pub(crate) fn make_test(
987
985
parser. maybe_consume_incorrect_semicolon ( & [ ] ) ;
988
986
}
989
987
990
- has_errors = has_errors || psess. dcx . has_errors_or_delayed_bugs ( ) . is_some ( ) ;
991
988
// Reset errors so that they won't be reported as compiler bugs when dropping the
992
989
// dcx. Any errors in the tests will be reported when the test file is compiled,
993
990
// Note that we still need to cancel the errors above otherwise `Diag` will panic on
994
991
// drop.
995
992
psess. dcx . reset_err_count ( ) ;
996
993
997
- ( found_main, found_extern_crate, found_macro, has_errors )
994
+ ( found_main, found_extern_crate, found_macro)
998
995
} )
999
996
} ) ;
1000
997
@@ -1003,7 +1000,7 @@ pub(crate) fn make_test(
1003
1000
Ignore :: None => false ,
1004
1001
Ignore :: Some ( ref ignores) => ignores. iter ( ) . any ( |s| target_str. contains ( s) ) ,
1005
1002
} ;
1006
- let Ok ( ( mut main_fn_span, already_has_extern_crate, found_macro, has_errors ) ) = result else {
1003
+ let Ok ( ( mut main_fn_span, already_has_extern_crate, found_macro) ) = result else {
1007
1004
// If the parser panicked due to a fatal error, pass the test code through unchanged.
1008
1005
// The error will be reported during compilation.
1009
1006
return DocTest {
@@ -1059,7 +1056,7 @@ pub(crate) fn make_test(
1059
1056
lang_string,
1060
1057
line,
1061
1058
file,
1062
- failed_ast : has_errors ,
1059
+ failed_ast : false ,
1063
1060
rustdoc_test_options,
1064
1061
outdir,
1065
1062
test_id,
@@ -1320,6 +1317,10 @@ impl DocTestKinds {
1320
1317
#![feature(coverage_attribute)]\n "
1321
1318
. to_string ( ) ;
1322
1319
1320
+ for doctest in & doctests {
1321
+ output. push_str ( & doctest. crate_attrs ) ;
1322
+ }
1323
+
1323
1324
DocTest :: push_attrs ( & mut output, & opts, & mut 0 ) ;
1324
1325
output. push_str ( "extern crate test;\n " ) ;
1325
1326
0 commit comments