@@ -24,8 +24,8 @@ use std::fs::File;
24
24
use std:: io:: prelude:: * ;
25
25
use std:: path:: Path ;
26
26
27
- #[ derive( PartialEq ) ]
28
- enum Status {
27
+ #[ derive( Debug , PartialEq ) ]
28
+ pub enum Status {
29
29
Stable ,
30
30
Removed ,
31
31
Unstable ,
@@ -42,78 +42,21 @@ impl fmt::Display for Status {
42
42
}
43
43
}
44
44
45
- struct Feature {
46
- level : Status ,
47
- since : String ,
48
- has_gate_test : bool ,
45
+ #[ derive( Debug ) ]
46
+ pub struct Feature {
47
+ pub level : Status ,
48
+ pub since : String ,
49
+ pub has_gate_test : bool ,
49
50
}
50
51
51
52
pub fn check ( path : & Path , bad : & mut bool ) {
52
- let mut features = collect_lang_features ( & path. join ( "libsyntax/feature_gate.rs" ) ) ;
53
+ let mut features = collect_lang_features ( path) ;
53
54
assert ! ( !features. is_empty( ) ) ;
54
- let mut lib_features = HashMap :: < String , Feature > :: new ( ) ;
55
-
56
- let mut contents = String :: new ( ) ;
57
- super :: walk ( path,
58
- & mut |path| super :: filter_dirs ( path) || path. ends_with ( "src/test" ) ,
59
- & mut |file| {
60
- let filename = file. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
61
- if !filename. ends_with ( ".rs" ) || filename == "features.rs" ||
62
- filename == "diagnostic_list.rs" {
63
- return ;
64
- }
65
-
66
- contents. truncate ( 0 ) ;
67
- t ! ( t!( File :: open( & file) , & file) . read_to_string( & mut contents) ) ;
68
55
69
- for ( i, line) in contents. lines ( ) . enumerate ( ) {
70
- let mut err = |msg : & str | {
71
- println ! ( "{}:{}: {}" , file. display( ) , i + 1 , msg) ;
72
- * bad = true ;
73
- } ;
74
- let level = if line. contains ( "[unstable(" ) {
75
- Status :: Unstable
76
- } else if line. contains ( "[stable(" ) {
77
- Status :: Stable
78
- } else {
79
- continue ;
80
- } ;
81
- let feature_name = match find_attr_val ( line, "feature" ) {
82
- Some ( name) => name,
83
- None => {
84
- err ( "malformed stability attribute" ) ;
85
- continue ;
86
- }
87
- } ;
88
- let since = match find_attr_val ( line, "since" ) {
89
- Some ( name) => name,
90
- None if level == Status :: Stable => {
91
- err ( "malformed stability attribute" ) ;
92
- continue ;
93
- }
94
- None => "None" ,
95
- } ;
56
+ let lib_features = collect_lib_features ( path, bad, & features) ;
57
+ assert ! ( !lib_features. is_empty( ) ) ;
96
58
97
- if features. contains_key ( feature_name) {
98
- err ( "duplicating a lang feature" ) ;
99
- }
100
- if let Some ( ref s) = lib_features. get ( feature_name) {
101
- if s. level != level {
102
- err ( "different stability level than before" ) ;
103
- }
104
- if s. since != since {
105
- err ( "different `since` than before" ) ;
106
- }
107
- continue ;
108
- }
109
- lib_features. insert ( feature_name. to_owned ( ) ,
110
- Feature {
111
- level : level,
112
- since : since. to_owned ( ) ,
113
- has_gate_test : false ,
114
- } ) ;
115
- }
116
- } ) ;
59
+ let mut contents = String :: new ( ) ;
117
60
118
61
super :: walk_many ( & [ & path. join ( "test/compile-fail" ) ,
119
62
& path. join ( "test/compile-fail-fulldeps" ) ,
@@ -233,8 +176,9 @@ fn test_filen_gate(filen_underscore: &str,
233
176
return false ;
234
177
}
235
178
236
- fn collect_lang_features ( path : & Path ) -> HashMap < String , Feature > {
179
+ pub fn collect_lang_features ( base_src_path : & Path ) -> HashMap < String , Feature > {
237
180
let mut contents = String :: new ( ) ;
181
+ let path = base_src_path. join ( "libsyntax/feature_gate.rs" ) ;
238
182
t ! ( t!( File :: open( path) ) . read_to_string( & mut contents) ) ;
239
183
240
184
contents. lines ( )
@@ -257,3 +201,71 @@ fn collect_lang_features(path: &Path) -> HashMap<String, Feature> {
257
201
} )
258
202
. collect ( )
259
203
}
204
+
205
+ pub fn collect_lib_features ( base_src_path : & Path ,
206
+ bad : & mut bool ,
207
+ features : & HashMap < String , Feature > ) -> HashMap < String , Feature > {
208
+ let mut lib_features = HashMap :: < String , Feature > :: new ( ) ;
209
+ let mut contents = String :: new ( ) ;
210
+ super :: walk ( base_src_path,
211
+ & mut |path| super :: filter_dirs ( path) || path. ends_with ( "src/test" ) ,
212
+ & mut |file| {
213
+ let filename = file. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
214
+ if !filename. ends_with ( ".rs" ) || filename == "features.rs" ||
215
+ filename == "diagnostic_list.rs" {
216
+ return ;
217
+ }
218
+
219
+ contents. truncate ( 0 ) ;
220
+ t ! ( t!( File :: open( & file) , & file) . read_to_string( & mut contents) ) ;
221
+
222
+ for ( i, line) in contents. lines ( ) . enumerate ( ) {
223
+ let mut err = |msg : & str | {
224
+ println ! ( "{}:{}: {}" , file. display( ) , i + 1 , msg) ;
225
+ * bad = true ;
226
+ } ;
227
+ let level = if line. contains ( "[unstable(" ) {
228
+ Status :: Unstable
229
+ } else if line. contains ( "[stable(" ) {
230
+ Status :: Stable
231
+ } else {
232
+ continue ;
233
+ } ;
234
+ let feature_name = match find_attr_val ( line, "feature" ) {
235
+ Some ( name) => name,
236
+ None => {
237
+ err ( "malformed stability attribute" ) ;
238
+ continue ;
239
+ }
240
+ } ;
241
+ let since = match find_attr_val ( line, "since" ) {
242
+ Some ( name) => name,
243
+ None if level == Status :: Stable => {
244
+ err ( "malformed stability attribute" ) ;
245
+ continue ;
246
+ }
247
+ None => "None" ,
248
+ } ;
249
+
250
+ if features. contains_key ( feature_name) {
251
+ err ( "duplicating a lang feature" ) ;
252
+ }
253
+ if let Some ( ref s) = lib_features. get ( feature_name) {
254
+ if s. level != level {
255
+ err ( "different stability level than before" ) ;
256
+ }
257
+ if s. since != since {
258
+ err ( "different `since` than before" ) ;
259
+ }
260
+ continue ;
261
+ }
262
+ lib_features. insert ( feature_name. to_owned ( ) ,
263
+ Feature {
264
+ level : level,
265
+ since : since. to_owned ( ) ,
266
+ has_gate_test : false ,
267
+ } ) ;
268
+ }
269
+ } ) ;
270
+ lib_features
271
+ }
0 commit comments