@@ -407,13 +407,23 @@ pub fn make_test(s: &str,
407
407
let ( already_has_main, already_has_extern_crate) = crate :: syntax:: with_globals ( || {
408
408
use crate :: syntax:: { ast, parse:: { self , ParseSess } , source_map:: FilePathMapping } ;
409
409
use crate :: syntax_pos:: FileName ;
410
+ use errors:: emitter:: EmitterWriter ;
411
+ use errors:: Handler ;
410
412
411
413
let filename = FileName :: Anon ;
412
414
let source = crates + & everything_else;
413
- let sess = ParseSess :: new ( FilePathMapping :: empty ( ) ) ;
415
+
416
+ // any errors in parsing should also appear when the doctest is compiled for real, so just
417
+ // send all the errors that libsyntax emits directly into a Sink instead of stderr
418
+ let cm = Lrc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
419
+ let emitter = EmitterWriter :: new ( box io:: sink ( ) , None , false , false ) ;
420
+ let handler = Handler :: with_emitter ( false , false , box emitter) ;
421
+ let sess = ParseSess :: with_span_handler ( handler, cm) ;
414
422
415
423
debug ! ( "about to parse: \n {}" , source) ;
416
424
425
+ // FIXME(misdreavus): this can still emit a FatalError (and thus halt rustdoc prematurely)
426
+ // if there is a lexing error in the first token
417
427
let mut parser = parse:: new_parser_from_source_str ( & sess, filename, source) ;
418
428
419
429
let mut found_main = false ;
0 commit comments