Skip to content

Commit 7786f70

Browse files
Add warning for invalid start of code blocks in rustdoc
1 parent 8aa27ee commit 7786f70

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/librustdoc/html/markdown.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
2828
#![allow(non_camel_case_types)]
2929

30+
use rustc::session;
3031
use std::cell::RefCell;
3132
use std::collections::{HashMap, VecDeque};
3233
use std::default::Default;
@@ -434,7 +435,8 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for Footnotes<'a, I> {
434435
}
435436
}
436437

437-
pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Span) {
438+
pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Span,
439+
sess: Option<&session::Session>) {
438440
tests.set_position(position);
439441

440442
let mut parser = Parser::new(doc);
@@ -484,6 +486,9 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
484486
line, filename, block_info.allow_fail);
485487
prev_offset = offset;
486488
} else {
489+
if let Some(ref sess) = sess {
490+
sess.span_warn(position, "invalid start of a new code block");
491+
}
487492
break;
488493
}
489494
}

src/librustdoc/markdown.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
152152
true, opts, maybe_sysroot, None,
153153
Some(PathBuf::from(input)),
154154
linker);
155-
find_testable_code(&input_str, &mut collector, DUMMY_SP);
155+
find_testable_code(&input_str, &mut collector, DUMMY_SP, None);
156156
test_args.insert(0, "rustdoctest".to_string());
157157
testing::test_main(&test_args, collector.tests,
158158
testing::Options::new().display_output(display_warnings));

src/librustdoc/test.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,10 @@ impl<'a, 'hir> HirCollector<'a, 'hir> {
645645
// the collapse-docs pass won't combine sugared/raw doc attributes, or included files with
646646
// anything else, this will combine them for us
647647
if let Some(doc) = attrs.collapsed_doc_value() {
648-
markdown::find_testable_code(&doc, self.collector,
649-
attrs.span.unwrap_or(DUMMY_SP));
648+
markdown::find_testable_code(&doc,
649+
self.collector,
650+
attrs.span.unwrap_or(DUMMY_SP),
651+
Some(self.sess));
650652
}
651653

652654
nested(self);

0 commit comments

Comments
 (0)