Provide warnings for invalid code blocks in markdown files

Previously we would only warn on Rust code but we can also do so when
testing markdown (the diag::Handler is available).
This commit is contained in:
Mark Rousskov 2018-07-21 16:30:02 -06:00
parent 0af5a6be05
commit ad40e4517f
3 changed files with 5 additions and 7 deletions

View File

@ -27,7 +27,6 @@
#![allow(non_camel_case_types)]
use rustc::session;
use std::cell::RefCell;
use std::collections::{HashMap, VecDeque};
use std::default::Default;
@ -37,6 +36,7 @@ use std::ops::Range;
use std::str;
use syntax::feature_gate::UnstableFeatures;
use syntax::codemap::Span;
use errors;
use html::render::derive_id;
use html::toc::TocBuilder;
@ -470,7 +470,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for Footnotes<'a, I> {
}
pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Span,
sess: Option<&session::Session>) {
handler: &errors::Handler) {
tests.set_position(position);
let is_nightly = UnstableFeatures::from_environment().is_nightly_build();
@ -521,9 +521,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
line, filename, block_info.allow_fail);
prev_offset = offset;
} else {
if let Some(ref sess) = sess {
sess.span_warn(position, "invalid start of a new code block");
}
handler.span_warn(position, "invalid start of a new code block");
break;
}
}

View File

@ -156,7 +156,7 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
true, opts, maybe_sysroot, None,
Some(PathBuf::from(input)),
linker, edition);
find_testable_code(&input_str, &mut collector, DUMMY_SP, None);
find_testable_code(&input_str, &mut collector, DUMMY_SP, diag);
test_args.insert(0, "rustdoctest".to_string());
testing::test_main(&test_args, collector.tests,
testing::Options::new().display_output(display_warnings));

View File

@ -692,7 +692,7 @@ impl<'a, 'hir> HirCollector<'a, 'hir> {
markdown::find_testable_code(&doc,
self.collector,
attrs.span.unwrap_or(DUMMY_SP),
Some(self.sess));
self.sess.diagnostic());
}
nested(self);