@@ -77,7 +77,7 @@ pub fn run(input: &str, libs: @RefCell<HashSet<Path>>, mut test_args: ~[~str]) -
7777 let ( krate, _) = passes:: unindent_comments ( krate) ;
7878 let ( krate, _) = passes:: collapse_docs ( krate) ;
7979
80- let mut collector = Collector :: new ( krate. name . to_owned ( ) , libs, false ) ;
80+ let mut collector = Collector :: new ( krate. name . to_owned ( ) , libs, false , false ) ;
8181 collector. fold_crate ( krate) ;
8282
8383 test_args. unshift ( ~"rustdoctest") ;
@@ -88,8 +88,8 @@ pub fn run(input: &str, libs: @RefCell<HashSet<Path>>, mut test_args: ~[~str]) -
8888}
8989
9090fn runtest ( test : & str , cratename : & str , libs : HashSet < Path > , should_fail : bool ,
91- no_run : bool ) {
92- let test = maketest ( test, cratename) ;
91+ no_run : bool , loose_feature_gating : bool ) {
92+ let test = maketest ( test, cratename, loose_feature_gating ) ;
9393 let parsesess = parse:: new_parse_sess ( ) ;
9494 let input = driver:: StrInput ( test) ;
9595
@@ -162,11 +162,18 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
162162 }
163163}
164164
165- fn maketest ( s : & str , cratename : & str ) -> ~str {
165+ fn maketest ( s : & str , cratename : & str , loose_feature_gating : bool ) -> ~str {
166166 let mut prog = ~r"
167167#[deny(warnings)];
168168#[allow(unused_variable, dead_assignment, unused_mut, attribute_usage, dead_code)];
169169" ;
170+
171+ if loose_feature_gating {
172+ // FIXME #12773: avoid inserting these when the tutorial & manual
173+ // etc. have been updated to not use them so prolifically.
174+ prog. push_str ( "#[ feature(macro_rules, globs, struct_variant, managed_boxes) ];\n " ) ;
175+ }
176+
170177 if !s. contains ( "extern crate" ) {
171178 if s. contains ( "extra" ) {
172179 prog. push_str ( "extern crate extra;\n " ) ;
@@ -194,18 +201,23 @@ pub struct Collector {
194201 priv use_headers : bool ,
195202 priv current_header : Option < ~str > ,
196203 priv cratename : ~str ,
204+
205+ priv loose_feature_gating : bool
197206}
198207
199208impl Collector {
200- pub fn new ( cratename : ~str , libs : @RefCell < HashSet < Path > > , use_headers : bool ) -> Collector {
209+ pub fn new ( cratename : ~str , libs : @RefCell < HashSet < Path > > ,
210+ use_headers : bool , loose_feature_gating : bool ) -> Collector {
201211 Collector {
202212 tests : ~[ ] ,
203213 names : ~[ ] ,
204214 libs : libs,
205215 cnt : 0 ,
206216 use_headers : use_headers,
207217 current_header : None ,
208- cratename : cratename
218+ cratename : cratename,
219+
220+ loose_feature_gating : loose_feature_gating
209221 }
210222 }
211223
@@ -220,6 +232,7 @@ impl Collector {
220232 let libs = self . libs . borrow ( ) ;
221233 let libs = ( * libs. get ( ) ) . clone ( ) ;
222234 let cratename = self . cratename . to_owned ( ) ;
235+ let loose_feature_gating = self . loose_feature_gating ;
223236 debug ! ( "Creating test {}: {}" , name, test) ;
224237 self . tests . push ( testing:: TestDescAndFn {
225238 desc : testing:: TestDesc {
@@ -228,7 +241,7 @@ impl Collector {
228241 should_fail : false , // compiler failures are test failures
229242 } ,
230243 testfn : testing:: DynTestFn ( proc ( ) {
231- runtest ( test, cratename, libs, should_fail, no_run) ;
244+ runtest ( test, cratename, libs, should_fail, no_run, loose_feature_gating ) ;
232245 } ) ,
233246 } ) ;
234247 }
0 commit comments