@@ -166,9 +166,18 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
166
166
compile_fail : bool , mut error_codes : Vec < String > , opts : & TestOptions ,
167
167
maybe_sysroot : Option < PathBuf > , linker : Option < PathBuf > , edition : Edition ,
168
168
persist_doctests : Option < PathBuf > ) {
169
- // The test harness wants its own `main` and top-level functions, so
170
- // never wrap the test in `fn main() { ... }`.
171
- let ( test, line_offset) = make_test ( test, Some ( cratename) , as_test_harness, opts) ;
169
+ let ( test, line_offset) = match panic:: catch_unwind ( || {
170
+ make_test ( test, Some ( cratename) , as_test_harness, opts)
171
+ } ) {
172
+ Ok ( ( test, line_offset) ) => ( test, line_offset) ,
173
+ Err ( cause) if cause. is :: < errors:: FatalErrorMarker > ( ) => {
174
+ // If the parser used by `make_test` panicked due to a fatal error, pass the test code
175
+ // through unchanged. The error will be reported during compilation.
176
+ ( test. to_owned ( ) , 0 )
177
+ } ,
178
+ Err ( cause) => panic:: resume_unwind ( cause) ,
179
+ } ;
180
+
172
181
// FIXME(#44940): if doctests ever support path remapping, then this filename
173
182
// needs to be the result of `SourceMap::span_to_unmapped_path`.
174
183
let path = match filename {
@@ -337,7 +346,13 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
337
346
}
338
347
}
339
348
340
- /// Makes the test file. Also returns the number of lines before the code begins
349
+ /// Transforms a test into code that can be compiled into a Rust binary, and returns the number of
350
+ /// lines before the test code begins.
351
+ ///
352
+ /// # Panics
353
+ ///
354
+ /// This function uses the compiler's parser internally. The parser will panic if it encounters a
355
+ /// fatal error while parsing the test.
341
356
pub fn make_test ( s : & str ,
342
357
cratename : Option < & str > ,
343
358
dont_insert_main : bool ,
0 commit comments