@@ -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 ( ) ,
@@ -846,7 +846,7 @@ pub const TEST: test::TestDescAndFn = test::TestDescAndFn {{
846
846
end_line: 0,
847
847
end_col: 0,
848
848
compile_fail: false,
849
- no_run: false ,
849
+ no_run: {no_run} ,
850
850
should_panic: test::ShouldPanic::{should_panic},
851
851
test_type: test::TestType::UnitTest,
852
852
}},
@@ -860,6 +860,7 @@ pub const TEST: test::TestDescAndFn = test::TestDescAndFn {{
860
860
ignore = self . ignore,
861
861
file = self . file,
862
862
line = self . line,
863
+ no_run = self . no_run,
863
864
should_panic = if !self . no_run && self . lang_string. should_panic { "Yes" } else { "No" } ,
864
865
// Setting `no_run` to `true` in `TestDesc` still makes the test run, so we simply
865
866
// don't give it the function to run.
@@ -942,11 +943,10 @@ pub(crate) fn make_test(
942
943
Ok ( p) => p,
943
944
Err ( errs) => {
944
945
errs. into_iter ( ) . for_each ( |err| err. cancel ( ) ) ;
945
- return ( found_main, found_extern_crate, found_macro, true ) ;
946
+ return ( found_main, found_extern_crate, found_macro) ;
946
947
}
947
948
} ;
948
949
949
- let mut has_errors = false ;
950
950
loop {
951
951
match parser. parse_item ( ForceCollect :: No ) {
952
952
Ok ( Some ( item) ) => {
@@ -977,7 +977,6 @@ pub(crate) fn make_test(
977
977
Ok ( None ) => break ,
978
978
Err ( e) => {
979
979
e. cancel ( ) ;
980
- has_errors = true ;
981
980
break ;
982
981
}
983
982
}
@@ -987,14 +986,13 @@ pub(crate) fn make_test(
987
986
parser. maybe_consume_incorrect_semicolon ( & [ ] ) ;
988
987
}
989
988
990
- has_errors = has_errors || psess. dcx . has_errors_or_delayed_bugs ( ) . is_some ( ) ;
991
989
// Reset errors so that they won't be reported as compiler bugs when dropping the
992
990
// dcx. Any errors in the tests will be reported when the test file is compiled,
993
991
// Note that we still need to cancel the errors above otherwise `Diag` will panic on
994
992
// drop.
995
993
psess. dcx . reset_err_count ( ) ;
996
994
997
- ( found_main, found_extern_crate, found_macro, has_errors )
995
+ ( found_main, found_extern_crate, found_macro)
998
996
} )
999
997
} ) ;
1000
998
@@ -1003,7 +1001,7 @@ pub(crate) fn make_test(
1003
1001
Ignore :: None => false ,
1004
1002
Ignore :: Some ( ref ignores) => ignores. iter ( ) . any ( |s| target_str. contains ( s) ) ,
1005
1003
} ;
1006
- let Ok ( ( mut main_fn_span, already_has_extern_crate, found_macro, has_errors ) ) = result else {
1004
+ let Ok ( ( mut main_fn_span, already_has_extern_crate, found_macro) ) = result else {
1007
1005
// If the parser panicked due to a fatal error, pass the test code through unchanged.
1008
1006
// The error will be reported during compilation.
1009
1007
return DocTest {
@@ -1059,7 +1057,7 @@ pub(crate) fn make_test(
1059
1057
lang_string,
1060
1058
line,
1061
1059
file,
1062
- failed_ast : has_errors ,
1060
+ failed_ast : false ,
1063
1061
rustdoc_test_options,
1064
1062
outdir,
1065
1063
test_id,
@@ -1320,6 +1318,10 @@ impl DocTestKinds {
1320
1318
#![feature(coverage_attribute)]\n "
1321
1319
. to_string ( ) ;
1322
1320
1321
+ for doctest in & doctests {
1322
+ output. push_str ( & doctest. crate_attrs ) ;
1323
+ }
1324
+
1323
1325
DocTest :: push_attrs ( & mut output, & opts, & mut 0 ) ;
1324
1326
output. push_str ( "extern crate test;\n " ) ;
1325
1327
0 commit comments