@@ -50,6 +50,34 @@ pub struct Feature {
50
50
pub tracking_issue : Option < u32 > ,
51
51
}
52
52
53
+ impl Feature {
54
+ fn check_match ( & self , other : & Feature ) -> Result < ( ) , Vec < & ' static str > > {
55
+ let mut mismatches = Vec :: new ( ) ;
56
+ if self . level != other. level {
57
+ mismatches. push ( "stability level" ) ;
58
+ }
59
+ if self . level == Status :: Stable || other. level == Status :: Stable {
60
+ // As long as a feature is unstable, the since field tracks
61
+ // when the given part of the feature has been implemented.
62
+ // Mismatches are tolerable as features evolve and functionality
63
+ // gets added.
64
+ // Once a feature is stable, the since field tracks the first version
65
+ // it was part of the stable distribution, and mismatches are disallowed.
66
+ if self . since != other. since {
67
+ mismatches. push ( "since" ) ;
68
+ }
69
+ }
70
+ if self . tracking_issue != other. tracking_issue {
71
+ mismatches. push ( "tracking issue" ) ;
72
+ }
73
+ if mismatches. is_empty ( ) {
74
+ Ok ( ( ) )
75
+ } else {
76
+ Err ( mismatches)
77
+ }
78
+ }
79
+ }
80
+
53
81
pub type Features = HashMap < String , Feature > ;
54
82
55
83
pub fn check ( path : & Path , bad : & mut bool , quiet : bool ) {
@@ -242,23 +270,20 @@ fn get_and_check_lib_features(base_src_path: &Path,
242
270
& mut |res, file, line| {
243
271
match res {
244
272
Ok ( ( name, f) ) => {
245
- let mut err = |msg : & str | {
246
- tidy_error ! ( bad, "{}:{}: {}" , file. display( ) , line, msg) ;
247
- } ;
248
- if lang_features. contains_key ( name) && name != "proc_macro" {
249
- err ( "duplicating a lang feature" ) ;
250
- }
251
- if let Some ( ref s) = lib_features. get ( name) {
252
- if s. level != f. level {
253
- err ( "different stability level than before" ) ;
254
- }
255
- if s. since != f. since {
256
- err ( "different `since` than before" ) ;
273
+ let mut check_features = |f : & Feature , list : & Features , display : & str | {
274
+ if let Some ( ref s) = list. get ( name) {
275
+ if let Err ( m) = ( & f) . check_match ( s) {
276
+ tidy_error ! ( bad,
277
+ "{}:{}: mismatches to {} in: {:?}" ,
278
+ file. display( ) ,
279
+ line,
280
+ display,
281
+ & m) ;
282
+ }
257
283
}
258
- if s. tracking_issue != f. tracking_issue {
259
- err ( "different `tracking_issue` than before" ) ;
260
- }
261
- }
284
+ } ;
285
+ check_features ( & f, & lang_features, "corresponding lang feature" ) ;
286
+ check_features ( & f, & lib_features, "previous" ) ;
262
287
lib_features. insert ( name. to_owned ( ) , f) ;
263
288
} ,
264
289
Err ( msg) => {
0 commit comments