]> git.lizzy.rs Git - rust.git/commitdiff
Pull out nightly checking to edges
authorMark Rousskov <mark.simulacrum@gmail.com>
Sat, 21 Jul 2018 22:12:16 +0000 (16:12 -0600)
committerMark Rousskov <mark.simulacrum@gmail.com>
Tue, 31 Jul 2018 17:37:21 +0000 (11:37 -0600)
Parsing the code block's LangString (```foo) previously checked itself
to see if we were on nightly; that isn't the right place to do so. Move
that check slightly outwards to better abstract LangString.

(This is also an optimization as we avoid the costly environment
variable load of RUSTC_BOOTSTRAP).

src/librustdoc/html/markdown.rs

index 8d85adfb3d0ff3a052dc317642808d32c550041f..d01745f4a46fad30f1dc6c1bedd893e50f2e57f9 100644 (file)
@@ -129,12 +129,14 @@ fn slugify(c: char) -> Option<char> {
 /// Adds syntax highlighting and playground Run buttons to rust code blocks.
 struct CodeBlocks<'a, I: Iterator<Item = Event<'a>>> {
     inner: I,
+    check_error_codes: bool,
 }
 
 impl<'a, I: Iterator<Item = Event<'a>>> CodeBlocks<'a, I> {
     fn new(iter: I) -> Self {
         CodeBlocks {
             inner: iter,
+            check_error_codes: UnstableFeatures::from_environment().is_nightly_build(),
         }
     }
 }
@@ -147,7 +149,7 @@ fn next(&mut self) -> Option<Self::Item> {
         let compile_fail;
         let ignore;
         if let Some(Event::Start(Tag::CodeBlock(lang))) = event {
-            let parse_result = LangString::parse(&lang);
+            let parse_result = LangString::parse(&lang, self.check_error_codes);
             if !parse_result.rust {
                 return Some(Event::Start(Tag::CodeBlock(lang)));
             }
@@ -471,6 +473,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
                           sess: Option<&session::Session>) {
     tests.set_position(position);
 
+    let is_nightly = UnstableFeatures::from_environment().is_nightly_build();
     let mut parser = Parser::new(doc);
     let mut prev_offset = 0;
     let mut nb_lines = 0;
@@ -481,7 +484,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
                 let block_info = if s.is_empty() {
                     LangString::all_false()
                 } else {
-                    LangString::parse(&*s)
+                    LangString::parse(&*s, is_nightly)
                 };
                 if !block_info.rust {
                     continue
@@ -569,14 +572,10 @@ fn all_false() -> LangString {
         }
     }
 
-    fn parse(string: &str) -> LangString {
+    fn parse(string: &str, allow_error_code_check: bool) -> LangString {
         let mut seen_rust_tags = false;
         let mut seen_other_tags = false;
         let mut data = LangString::all_false();
-        let mut allow_error_code_check = false;
-        if UnstableFeatures::from_environment().is_nightly_build() {
-            allow_error_code_check = true;
-        }
 
         data.original = string.to_owned();
         let tokens = string.split(|c: char|
@@ -842,7 +841,7 @@ fn test_lang_string_parse() {
         fn t(s: &str,
             should_panic: bool, no_run: bool, ignore: bool, rust: bool, test_harness: bool,
             compile_fail: bool, allow_fail: bool, error_codes: Vec<String>) {
-            assert_eq!(LangString::parse(s), LangString {
+            assert_eq!(LangString::parse(s, true), LangString {
                 should_panic,
                 no_run,
                 ignore,