Skip to content

Commit ad40e45

Browse files
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).
1 parent 0af5a6b commit ad40e45

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/librustdoc/html/markdown.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
2828
#![allow(non_camel_case_types)]
2929

30-
use rustc::session;
3130
use std::cell::RefCell;
3231
use std::collections::{HashMap, VecDeque};
3332
use std::default::Default;
@@ -37,6 +36,7 @@ use std::ops::Range;
3736
use std::str;
3837
use syntax::feature_gate::UnstableFeatures;
3938
use syntax::codemap::Span;
39+
use errors;
4040

4141
use html::render::derive_id;
4242
use html::toc::TocBuilder;
@@ -470,7 +470,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for Footnotes<'a, I> {
470470
}
471471

472472
pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Span,
473-
sess: Option<&session::Session>) {
473+
handler: &errors::Handler) {
474474
tests.set_position(position);
475475

476476
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
521521
line, filename, block_info.allow_fail);
522522
prev_offset = offset;
523523
} else {
524-
if let Some(ref sess) = sess {
525-
sess.span_warn(position, "invalid start of a new code block");
526-
}
524+
handler.span_warn(position, "invalid start of a new code block");
527525
break;
528526
}
529527
}

src/librustdoc/markdown.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
156156
true, opts, maybe_sysroot, None,
157157
Some(PathBuf::from(input)),
158158
linker, edition);
159-
find_testable_code(&input_str, &mut collector, DUMMY_SP, None);
159+
find_testable_code(&input_str, &mut collector, DUMMY_SP, diag);
160160
test_args.insert(0, "rustdoctest".to_string());
161161
testing::test_main(&test_args, collector.tests,
162162
testing::Options::new().display_output(display_warnings));

src/librustdoc/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ impl<'a, 'hir> HirCollector<'a, 'hir> {
692692
markdown::find_testable_code(&doc,
693693
self.collector,
694694
attrs.span.unwrap_or(DUMMY_SP),
695-
Some(self.sess));
695+
self.sess.diagnostic());
696696
}
697697

698698
nested(self);

0 commit comments

Comments
 (0)