]> git.lizzy.rs Git - rust.git/commitdiff
Add warning for invalid start of code blocks in rustdoc
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 28 Feb 2018 00:09:30 +0000 (01:09 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Sun, 18 Mar 2018 19:34:49 +0000 (20:34 +0100)
src/librustdoc/html/markdown.rs
src/librustdoc/markdown.rs
src/librustdoc/test.rs

index 5e55353a26e6b49fe9a692a7ea61c23b3dfea59e..5ce3d57f82f23f79dc6255b572940fc45da84080 100644 (file)
@@ -27,6 +27,7 @@
 
 #![allow(non_camel_case_types)]
 
+use rustc::session;
 use std::cell::RefCell;
 use std::collections::{HashMap, VecDeque};
 use std::default::Default;
@@ -434,7 +435,8 @@ fn next(&mut self) -> Option<Self::Item> {
     }
 }
 
-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>) {
     tests.set_position(position);
 
     let mut parser = Parser::new(doc);
@@ -484,6 +486,9 @@ 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");
+                    }
                     break;
                 }
             }
index 0f107457d2bf88815927dbc36de0bfc679da5948..3a55b279b5cc701914f4330513a1b53320976c65 100644 (file)
@@ -152,7 +152,7 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
                                        true, opts, maybe_sysroot, None,
                                        Some(PathBuf::from(input)),
                                        linker);
-    find_testable_code(&input_str, &mut collector, DUMMY_SP);
+    find_testable_code(&input_str, &mut collector, DUMMY_SP, None);
     test_args.insert(0, "rustdoctest".to_string());
     testing::test_main(&test_args, collector.tests,
                        testing::Options::new().display_output(display_warnings));
index 117b21d47587f830121b43e9c2ff46b375b1dce3..707d5a12bbf9f53df8f6adf9f353df25eda30991 100644 (file)
@@ -645,8 +645,10 @@ fn visit_testable<F: FnOnce(&mut Self)>(&mut self,
         // the collapse-docs pass won't combine sugared/raw doc attributes, or included files with
         // anything else, this will combine them for us
         if let Some(doc) = attrs.collapsed_doc_value() {
-            markdown::find_testable_code(&doc, self.collector,
-                                         attrs.span.unwrap_or(DUMMY_SP));
+            markdown::find_testable_code(&doc,
+                                         self.collector,
+                                         attrs.span.unwrap_or(DUMMY_SP),
+                                         Some(self.sess));
         }
 
         nested(self);