Skip to content

Commit 8a3b5e9

Browse files
silence errors found during doctest pre-parsing
1 parent d6d8c6b commit 8a3b5e9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/librustdoc/test.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,23 @@ pub fn make_test(s: &str,
407407
let (already_has_main, already_has_extern_crate) = crate::syntax::with_globals(|| {
408408
use crate::syntax::{ast, parse::{self, ParseSess}, source_map::FilePathMapping};
409409
use crate::syntax_pos::FileName;
410+
use errors::emitter::EmitterWriter;
411+
use errors::Handler;
410412

411413
let filename = FileName::Anon;
412414
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);
414422

415423
debug!("about to parse: \n{}", source);
416424

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
417427
let mut parser = parse::new_parser_from_source_str(&sess, filename, source);
418428

419429
let mut found_main = false;

0 commit comments

Comments
 (0)