@@ -129,12 +129,14 @@ thread_local!(pub static PLAYGROUND: RefCell<Option<(Option<String>, String)>> =
129
129
/// Adds syntax highlighting and playground Run buttons to rust code blocks.
130
130
struct CodeBlocks < ' a , I : Iterator < Item = Event < ' a > > > {
131
131
inner : I ,
132
+ check_error_codes : bool ,
132
133
}
133
134
134
135
impl < ' a , I : Iterator < Item = Event < ' a > > > CodeBlocks < ' a , I > {
135
136
fn new ( iter : I ) -> Self {
136
137
CodeBlocks {
137
138
inner : iter,
139
+ check_error_codes : UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) ,
138
140
}
139
141
}
140
142
}
@@ -147,7 +149,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
147
149
let compile_fail;
148
150
let ignore;
149
151
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 ) ;
151
153
if !parse_result. rust {
152
154
return Some ( Event :: Start ( Tag :: CodeBlock ( lang) ) ) ;
153
155
}
@@ -471,6 +473,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
471
473
sess : Option < & session:: Session > ) {
472
474
tests. set_position ( position) ;
473
475
476
+ let is_nightly = UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) ;
474
477
let mut parser = Parser :: new ( doc) ;
475
478
let mut prev_offset = 0 ;
476
479
let mut nb_lines = 0 ;
@@ -481,7 +484,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
481
484
let block_info = if s. is_empty ( ) {
482
485
LangString :: all_false ( )
483
486
} else {
484
- LangString :: parse ( & * s)
487
+ LangString :: parse ( & * s, is_nightly )
485
488
} ;
486
489
if !block_info. rust {
487
490
continue
@@ -569,14 +572,10 @@ impl LangString {
569
572
}
570
573
}
571
574
572
- fn parse ( string : & str ) -> LangString {
575
+ fn parse ( string : & str , allow_error_code_check : bool ) -> LangString {
573
576
let mut seen_rust_tags = false ;
574
577
let mut seen_other_tags = false ;
575
578
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
- }
580
579
581
580
data. original = string. to_owned ( ) ;
582
581
let tokens = string. split ( |c : char |
@@ -842,7 +841,7 @@ mod tests {
842
841
fn t ( s : & str ,
843
842
should_panic : bool , no_run : bool , ignore : bool , rust : bool , test_harness : bool ,
844
843
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 {
846
845
should_panic,
847
846
no_run,
848
847
ignore,
0 commit comments