@@ -603,6 +603,11 @@ impl DocTest {
603
603
// If `test_id` is `None`, it means we're generating code for a code example "run" link.
604
604
test_id : Option < & str > ,
605
605
) -> ( 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
+ }
606
611
let mut line_offset = 0 ;
607
612
let mut prog = String :: with_capacity (
608
613
self . test_code . len ( ) + self . crate_attrs . len ( ) + self . crates . len ( ) ,
@@ -942,11 +947,10 @@ pub(crate) fn make_test(
942
947
Ok ( p) => p,
943
948
Err ( errs) => {
944
949
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) ;
946
951
}
947
952
} ;
948
953
949
- let mut has_errors = false ;
950
954
loop {
951
955
match parser. parse_item ( ForceCollect :: No ) {
952
956
Ok ( Some ( item) ) => {
@@ -977,7 +981,6 @@ pub(crate) fn make_test(
977
981
Ok ( None ) => break ,
978
982
Err ( e) => {
979
983
e. cancel ( ) ;
980
- has_errors = true ;
981
984
break ;
982
985
}
983
986
}
@@ -987,14 +990,13 @@ pub(crate) fn make_test(
987
990
parser. maybe_consume_incorrect_semicolon ( & [ ] ) ;
988
991
}
989
992
990
- has_errors = has_errors || psess. dcx . has_errors_or_delayed_bugs ( ) . is_some ( ) ;
991
993
// Reset errors so that they won't be reported as compiler bugs when dropping the
992
994
// dcx. Any errors in the tests will be reported when the test file is compiled,
993
995
// Note that we still need to cancel the errors above otherwise `Diag` will panic on
994
996
// drop.
995
997
psess. dcx . reset_err_count ( ) ;
996
998
997
- ( found_main, found_extern_crate, found_macro, has_errors )
999
+ ( found_main, found_extern_crate, found_macro)
998
1000
} )
999
1001
} ) ;
1000
1002
@@ -1003,7 +1005,7 @@ pub(crate) fn make_test(
1003
1005
Ignore :: None => false ,
1004
1006
Ignore :: Some ( ref ignores) => ignores. iter ( ) . any ( |s| target_str. contains ( s) ) ,
1005
1007
} ;
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 {
1007
1009
// If the parser panicked due to a fatal error, pass the test code through unchanged.
1008
1010
// The error will be reported during compilation.
1009
1011
return DocTest {
@@ -1059,7 +1061,7 @@ pub(crate) fn make_test(
1059
1061
lang_string,
1060
1062
line,
1061
1063
file,
1062
- failed_ast : has_errors ,
1064
+ failed_ast : false ,
1063
1065
rustdoc_test_options,
1064
1066
outdir,
1065
1067
test_id,
0 commit comments