Skip to content

Commit 0af5a6b

Browse files
Pull out nightly checking to edges
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).
1 parent f898179 commit 0af5a6b

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/librustdoc/html/markdown.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ thread_local!(pub static PLAYGROUND: RefCell<Option<(Option<String>, String)>> =
129129
/// Adds syntax highlighting and playground Run buttons to rust code blocks.
130130
struct CodeBlocks<'a, I: Iterator<Item = Event<'a>>> {
131131
inner: I,
132+
check_error_codes: bool,
132133
}
133134

134135
impl<'a, I: Iterator<Item = Event<'a>>> CodeBlocks<'a, I> {
135136
fn new(iter: I) -> Self {
136137
CodeBlocks {
137138
inner: iter,
139+
check_error_codes: UnstableFeatures::from_environment().is_nightly_build(),
138140
}
139141
}
140142
}
@@ -147,7 +149,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
147149
let compile_fail;
148150
let ignore;
149151
if let Some(Event::Start(Tag::CodeBlock(lang))) = event {
150-
let parse_result = LangString::parse(&lang);
152+
let parse_result = LangString::parse(&lang, self.check_error_codes);
151153
if !parse_result.rust {
152154
return Some(Event::Start(Tag::CodeBlock(lang)));
153155
}
@@ -471,6 +473,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
471473
sess: Option<&session::Session>) {
472474
tests.set_position(position);
473475

476+
let is_nightly = UnstableFeatures::from_environment().is_nightly_build();
474477
let mut parser = Parser::new(doc);
475478
let mut prev_offset = 0;
476479
let mut nb_lines = 0;
@@ -481,7 +484,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
481484
let block_info = if s.is_empty() {
482485
LangString::all_false()
483486
} else {
484-
LangString::parse(&*s)
487+
LangString::parse(&*s, is_nightly)
485488
};
486489
if !block_info.rust {
487490
continue
@@ -569,14 +572,10 @@ impl LangString {
569572
}
570573
}
571574

572-
fn parse(string: &str) -> LangString {
575+
fn parse(string: &str, allow_error_code_check: bool) -> LangString {
573576
let mut seen_rust_tags = false;
574577
let mut seen_other_tags = false;
575578
let mut data = LangString::all_false();
576-
let mut allow_error_code_check = false;
577-
if UnstableFeatures::from_environment().is_nightly_build() {
578-
allow_error_code_check = true;
579-
}
580579

581580
data.original = string.to_owned();
582581
let tokens = string.split(|c: char|
@@ -842,7 +841,7 @@ mod tests {
842841
fn t(s: &str,
843842
should_panic: bool, no_run: bool, ignore: bool, rust: bool, test_harness: bool,
844843
compile_fail: bool, allow_fail: bool, error_codes: Vec<String>) {
845-
assert_eq!(LangString::parse(s), LangString {
844+
assert_eq!(LangString::parse(s, true), LangString {
846845
should_panic,
847846
no_run,
848847
ignore,

0 commit comments

Comments
 (0)