@@ -603,6 +603,11 @@ impl DocTest {
603603 // If `test_id` is `None`, it means we're generating code for a code example "run" link.
604604 test_id : Option < & str > ,
605605 ) -> ( String , usize ) {
606+ if self . failed_ast {
607+ // If the AST failed to compile, no need to go generate a complete doctest, the error
608+ // will be better this way.
609+ return ( self . everything_else . clone ( ) , 0 ) ;
610+ }
606611 let mut line_offset = 0 ;
607612 let mut prog = String :: with_capacity (
608613 self . test_code . len ( ) + self . crate_attrs . len ( ) + self . crates . len ( ) ,
@@ -942,11 +947,10 @@ pub(crate) fn make_test(
942947 Ok ( p) => p,
943948 Err ( errs) => {
944949 errs. into_iter ( ) . for_each ( |err| err. cancel ( ) ) ;
945- return ( found_main, found_extern_crate, found_macro, true ) ;
950+ return ( found_main, found_extern_crate, found_macro) ;
946951 }
947952 } ;
948953
949- let mut has_errors = false ;
950954 loop {
951955 match parser. parse_item ( ForceCollect :: No ) {
952956 Ok ( Some ( item) ) => {
@@ -977,7 +981,6 @@ pub(crate) fn make_test(
977981 Ok ( None ) => break ,
978982 Err ( e) => {
979983 e. cancel ( ) ;
980- has_errors = true ;
981984 break ;
982985 }
983986 }
@@ -987,14 +990,13 @@ pub(crate) fn make_test(
987990 parser. maybe_consume_incorrect_semicolon ( & [ ] ) ;
988991 }
989992
990- has_errors = has_errors || psess. dcx . has_errors_or_delayed_bugs ( ) . is_some ( ) ;
991993 // Reset errors so that they won't be reported as compiler bugs when dropping the
992994 // dcx. Any errors in the tests will be reported when the test file is compiled,
993995 // Note that we still need to cancel the errors above otherwise `Diag` will panic on
994996 // drop.
995997 psess. dcx . reset_err_count ( ) ;
996998
997- ( found_main, found_extern_crate, found_macro, has_errors )
999+ ( found_main, found_extern_crate, found_macro)
9981000 } )
9991001 } ) ;
10001002
@@ -1003,7 +1005,7 @@ pub(crate) fn make_test(
10031005 Ignore :: None => false ,
10041006 Ignore :: Some ( ref ignores) => ignores. iter ( ) . any ( |s| target_str. contains ( s) ) ,
10051007 } ;
1006- let Ok ( ( mut main_fn_span, already_has_extern_crate, found_macro, has_errors ) ) = result else {
1008+ let Ok ( ( mut main_fn_span, already_has_extern_crate, found_macro) ) = result else {
10071009 // If the parser panicked due to a fatal error, pass the test code through unchanged.
10081010 // The error will be reported during compilation.
10091011 return DocTest {
@@ -1059,7 +1061,7 @@ pub(crate) fn make_test(
10591061 lang_string,
10601062 line,
10611063 file,
1062- failed_ast : has_errors ,
1064+ failed_ast : false ,
10631065 rustdoc_test_options,
10641066 outdir,
10651067 test_id,
0 commit comments