@@ -37,8 +37,7 @@ use crate::config::Options as RustdocOptions;
37
37
use crate :: html:: markdown:: { ErrorCodes , Ignore , LangString } ;
38
38
use crate :: lint:: init_lints;
39
39
40
- use self :: markdown:: MdDoctest ;
41
- use self :: rust:: { HirCollector , RustDoctest } ;
40
+ use self :: rust:: HirCollector ;
42
41
43
42
/// Options that apply to all doctests in a crate or Markdown file (for `rustdoc foo.md`).
44
43
#[ derive( Clone , Default ) ]
@@ -194,7 +193,7 @@ pub(crate) fn run(
194
193
tcx,
195
194
) ;
196
195
let tests = hir_collector. collect_crate ( ) ;
197
- tests. into_iter ( ) . for_each ( |t| collector. add_test ( ScrapedDoctest :: Rust ( t ) ) ) ;
196
+ tests. into_iter ( ) . for_each ( |t| collector. add_test ( t ) ) ;
198
197
199
198
collector
200
199
} ) ;
@@ -977,9 +976,12 @@ impl IndividualTestOptions {
977
976
}
978
977
979
978
/// A doctest scraped from the code, ready to be turned into a runnable test.
980
- enum ScrapedDoctest {
981
- Rust ( RustDoctest ) ,
982
- Markdown ( MdDoctest ) ,
979
+ struct ScrapedDoctest {
980
+ filename : FileName ,
981
+ line : usize ,
982
+ logical_path : Vec < String > ,
983
+ langstr : LangString ,
984
+ text : String ,
983
985
}
984
986
985
987
pub ( crate ) trait DoctestVisitor {
@@ -1031,27 +1033,18 @@ impl CreateRunnableDoctests {
1031
1033
}
1032
1034
1033
1035
fn add_test ( & mut self , test : ScrapedDoctest ) {
1034
- let ( filename, line, logical_path, langstr, text) = match test {
1035
- ScrapedDoctest :: Rust ( RustDoctest { filename, line, logical_path, langstr, text } ) => {
1036
- ( filename, line, logical_path, langstr, text)
1037
- }
1038
- ScrapedDoctest :: Markdown ( MdDoctest { filename, line, logical_path, langstr, text } ) => {
1039
- ( filename, line, logical_path, langstr, text)
1040
- }
1041
- } ;
1042
-
1043
- let name = self . generate_name ( & filename, line, & logical_path) ;
1036
+ let name = self . generate_name ( & test. filename , test. line , & test. logical_path ) ;
1044
1037
let crate_name = self . crate_name . clone ( ) ;
1045
1038
let opts = self . opts . clone ( ) ;
1046
- let edition = langstr. edition . unwrap_or ( self . rustdoc_options . edition ) ;
1039
+ let edition = test . langstr . edition . unwrap_or ( self . rustdoc_options . edition ) ;
1047
1040
let target_str = self . rustdoc_options . target . to_string ( ) ;
1048
1041
let unused_externs = self . unused_extern_reports . clone ( ) ;
1049
- let no_run = langstr. no_run || self . rustdoc_options . no_run ;
1050
- if !langstr. compile_fail {
1042
+ let no_run = test . langstr . no_run || self . rustdoc_options . no_run ;
1043
+ if !test . langstr . compile_fail {
1051
1044
self . compiling_test_count . fetch_add ( 1 , Ordering :: SeqCst ) ;
1052
1045
}
1053
1046
1054
- let path = match & filename {
1047
+ let path = match & test . filename {
1055
1048
FileName :: Real ( path) => {
1056
1049
if let Some ( local_path) = path. local_path ( ) {
1057
1050
local_path. to_path_buf ( )
@@ -1064,7 +1057,8 @@ impl CreateRunnableDoctests {
1064
1057
} ;
1065
1058
1066
1059
// For example `module/file.rs` would become `module_file_rs`
1067
- let file = filename
1060
+ let file = test
1061
+ . filename
1068
1062
. prefer_local ( )
1069
1063
. to_string_lossy ( )
1070
1064
. chars ( )
@@ -1073,22 +1067,25 @@ impl CreateRunnableDoctests {
1073
1067
let test_id = format ! (
1074
1068
"{file}_{line}_{number}" ,
1075
1069
file = file,
1076
- line = line,
1070
+ line = test . line,
1077
1071
number = {
1078
1072
// Increases the current test number, if this file already
1079
1073
// exists or it creates a new entry with a test number of 0.
1080
- self . visited_tests. entry( ( file. clone( ) , line) ) . and_modify( |v| * v += 1 ) . or_insert( 0 )
1074
+ self . visited_tests
1075
+ . entry( ( file. clone( ) , test. line) )
1076
+ . and_modify( |v| * v += 1 )
1077
+ . or_insert( 0 )
1081
1078
} ,
1082
1079
) ;
1083
1080
1084
1081
let rustdoc_test_options =
1085
1082
IndividualTestOptions :: new ( & self . rustdoc_options , & self . arg_file , test_id) ;
1086
1083
1087
- debug ! ( "creating test {name}: {text}" ) ;
1084
+ debug ! ( "creating test {name}: {}" , test . text ) ;
1088
1085
self . tests . push ( test:: TestDescAndFn {
1089
1086
desc : test:: TestDesc {
1090
1087
name : test:: DynTestName ( name) ,
1091
- ignore : match langstr. ignore {
1088
+ ignore : match test . langstr . ignore {
1092
1089
Ignore :: All => true ,
1093
1090
Ignore :: None => false ,
1094
1091
Ignore :: Some ( ref ignores) => ignores. iter ( ) . any ( |s| target_str. contains ( s) ) ,
@@ -1101,22 +1098,20 @@ impl CreateRunnableDoctests {
1101
1098
end_col : 0 ,
1102
1099
// compiler failures are test failures
1103
1100
should_panic : test:: ShouldPanic :: No ,
1104
- compile_fail : langstr. compile_fail ,
1101
+ compile_fail : test . langstr . compile_fail ,
1105
1102
no_run,
1106
1103
test_type : test:: TestType :: DocTest ,
1107
1104
} ,
1108
1105
testfn : test:: DynTestFn ( Box :: new ( move || {
1109
1106
doctest_run_fn (
1110
1107
RunnableDoctest {
1111
1108
crate_name,
1112
- line,
1113
1109
rustdoc_test_options,
1114
- langstr,
1115
1110
no_run,
1116
1111
opts,
1117
1112
edition,
1118
1113
path,
1119
- text ,
1114
+ scraped_test : test ,
1120
1115
} ,
1121
1116
unused_externs,
1122
1117
)
@@ -1128,45 +1123,31 @@ impl CreateRunnableDoctests {
1128
1123
/// A doctest that is ready to run.
1129
1124
struct RunnableDoctest {
1130
1125
crate_name : String ,
1131
- line : usize ,
1132
1126
rustdoc_test_options : IndividualTestOptions ,
1133
- langstr : LangString ,
1134
1127
no_run : bool ,
1135
1128
opts : GlobalTestOptions ,
1136
1129
edition : Edition ,
1137
1130
path : PathBuf ,
1138
- text : String ,
1131
+ scraped_test : ScrapedDoctest ,
1139
1132
}
1140
1133
1141
1134
fn doctest_run_fn (
1142
- test : RunnableDoctest ,
1135
+ runnable_test : RunnableDoctest ,
1143
1136
unused_externs : Arc < Mutex < Vec < UnusedExterns > > > ,
1144
1137
) -> Result < ( ) , String > {
1145
- let RunnableDoctest {
1146
- crate_name,
1147
- line,
1148
- rustdoc_test_options,
1149
- langstr,
1150
- no_run,
1151
- opts,
1152
- edition,
1153
- path,
1154
- text,
1155
- } = test;
1156
-
1157
1138
let report_unused_externs = |uext| {
1158
1139
unused_externs. lock ( ) . unwrap ( ) . push ( uext) ;
1159
1140
} ;
1160
1141
let res = run_test (
1161
- & text,
1162
- & crate_name,
1163
- line,
1164
- rustdoc_test_options,
1165
- langstr,
1166
- no_run,
1167
- & opts,
1168
- edition,
1169
- path,
1142
+ & runnable_test . scraped_test . text ,
1143
+ & runnable_test . crate_name ,
1144
+ runnable_test . scraped_test . line ,
1145
+ runnable_test . rustdoc_test_options ,
1146
+ runnable_test . scraped_test . langstr ,
1147
+ runnable_test . no_run ,
1148
+ & runnable_test . opts ,
1149
+ runnable_test . edition ,
1150
+ runnable_test . path ,
1170
1151
report_unused_externs,
1171
1152
) ;
1172
1153
0 commit comments