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