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:
parent
0af5a6be05
commit
ad40e4517f
3 changed files with 5 additions and 7 deletions
|
@ -27,7 +27,6 @@
|
||||||
|
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
|
|
||||||
use rustc::session;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
@ -37,6 +36,7 @@ use std::ops::Range;
|
||||||
use std::str;
|
use std::str;
|
||||||
use syntax::feature_gate::UnstableFeatures;
|
use syntax::feature_gate::UnstableFeatures;
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
|
use errors;
|
||||||
|
|
||||||
use html::render::derive_id;
|
use html::render::derive_id;
|
||||||
use html::toc::TocBuilder;
|
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,
|
pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Span,
|
||||||
sess: Option<&session::Session>) {
|
handler: &errors::Handler) {
|
||||||
tests.set_position(position);
|
tests.set_position(position);
|
||||||
|
|
||||||
let is_nightly = UnstableFeatures::from_environment().is_nightly_build();
|
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);
|
line, filename, block_info.allow_fail);
|
||||||
prev_offset = offset;
|
prev_offset = offset;
|
||||||
} else {
|
} else {
|
||||||
if let Some(ref sess) = sess {
|
handler.span_warn(position, "invalid start of a new code block");
|
||||||
sess.span_warn(position, "invalid start of a new code block");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,7 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
|
||||||
true, opts, maybe_sysroot, None,
|
true, opts, maybe_sysroot, None,
|
||||||
Some(PathBuf::from(input)),
|
Some(PathBuf::from(input)),
|
||||||
linker, edition);
|
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());
|
test_args.insert(0, "rustdoctest".to_string());
|
||||||
testing::test_main(&test_args, collector.tests,
|
testing::test_main(&test_args, collector.tests,
|
||||||
testing::Options::new().display_output(display_warnings));
|
testing::Options::new().display_output(display_warnings));
|
||||||
|
|
|
@ -692,7 +692,7 @@ impl<'a, 'hir> HirCollector<'a, 'hir> {
|
||||||
markdown::find_testable_code(&doc,
|
markdown::find_testable_code(&doc,
|
||||||
self.collector,
|
self.collector,
|
||||||
attrs.span.unwrap_or(DUMMY_SP),
|
attrs.span.unwrap_or(DUMMY_SP),
|
||||||
Some(self.sess));
|
self.sess.diagnostic());
|
||||||
}
|
}
|
||||||
|
|
||||||
nested(self);
|
nested(self);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue