1
- use super :: active:: { ACTIVE_FEATURES , Features } ;
1
+ use super :: { active:: { ACTIVE_FEATURES , Features } , Feature , State as FeatureState } ;
2
2
use super :: accepted:: ACCEPTED_FEATURES ;
3
3
use super :: removed:: { REMOVED_FEATURES , STABLE_REMOVED_FEATURES } ;
4
4
use super :: builtin_attrs:: { AttributeGate , AttributeType , BuiltinAttribute , BUILTIN_ATTRIBUTE_MAP } ;
@@ -127,17 +127,16 @@ pub fn check_attribute(attr: &ast::Attribute, parse_sess: &ParseSess, features:
127
127
}
128
128
129
129
fn find_lang_feature_issue ( feature : Symbol ) -> Option < u32 > {
130
- if let Some ( info) = ACTIVE_FEATURES . iter ( ) . find ( |t| t. 0 == feature) {
131
- let issue = info. 2 ;
130
+ if let Some ( info) = ACTIVE_FEATURES . iter ( ) . find ( |t| t. name == feature) {
132
131
// FIXME (#28244): enforce that active features have issue numbers
133
- // assert!(issue.is_some())
134
- issue
132
+ // assert!(info. issue.is_some())
133
+ info . issue
135
134
} else {
136
135
// search in Accepted, Removed, or Stable Removed features
137
136
let found = ACCEPTED_FEATURES . iter ( ) . chain ( REMOVED_FEATURES ) . chain ( STABLE_REMOVED_FEATURES )
138
- . find ( |t| t. 0 == feature) ;
137
+ . find ( |t| t. name == feature) ;
139
138
match found {
140
- Some ( & ( _ , _ , issue, _ ) ) => issue,
139
+ Some ( & Feature { issue, .. } ) => issue,
141
140
None => panic ! ( "Feature `{}` is not declared anywhere" , feature) ,
142
141
}
143
142
}
@@ -733,14 +732,11 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
733
732
}
734
733
}
735
734
736
- for & ( name, .., f_edition, set) in ACTIVE_FEATURES {
737
- if let Some ( f_edition) = f_edition {
738
- if f_edition <= crate_edition {
739
- set ( & mut features, DUMMY_SP ) ;
740
- edition_enabled_features. insert ( name, crate_edition) ;
741
- }
742
- }
743
- }
735
+ active_features_up_to ( crate_edition)
736
+ . for_each ( |f| {
737
+ f. set ( & mut features, DUMMY_SP ) ;
738
+ edition_enabled_features. insert ( f. name , crate_edition) ;
739
+ } ) ;
744
740
745
741
// Process the edition umbrella feature-gates first, to ensure
746
742
// `edition_enabled_features` is completed before it's queried.
@@ -761,21 +757,19 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
761
757
762
758
let name = mi. name_or_empty ( ) ;
763
759
764
- if let Some ( edition) = ALL_EDITIONS . iter ( ) . find ( |e| name == e. feature_name ( ) ) {
765
- if * edition <= crate_edition {
760
+ if let Some ( edition) = ALL_EDITIONS . iter ( ) . find ( |e| name == e. feature_name ( ) ) . copied ( ) {
761
+ if edition <= crate_edition {
766
762
continue ;
767
763
}
768
764
769
- for & ( name, .., f_edition, set) in ACTIVE_FEATURES {
770
- if let Some ( f_edition) = f_edition {
771
- if f_edition <= * edition {
772
- // FIXME(Manishearth) there is currently no way to set
773
- // lib features by edition
774
- set ( & mut features, DUMMY_SP ) ;
775
- edition_enabled_features. insert ( name, * edition) ;
776
- }
777
- }
778
- }
765
+ active_features_up_to ( edition)
766
+ . for_each ( |f| {
767
+ // FIXME(Manishearth) there is currently no way to set
768
+ // lib features by edition
769
+
770
+ f. set ( & mut features, DUMMY_SP ) ;
771
+ edition_enabled_features. insert ( name, edition) ;
772
+ } ) ;
779
773
}
780
774
}
781
775
}
@@ -829,14 +823,18 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
829
823
continue ;
830
824
}
831
825
832
- let removed = REMOVED_FEATURES . iter ( ) . find ( |f| name == f. 0 ) ;
833
- let stable_removed = STABLE_REMOVED_FEATURES . iter ( ) . find ( |f| name == f. 0 ) ;
834
- if let Some ( ( .., reason) ) = removed. or ( stable_removed) {
835
- feature_removed ( span_handler, mi. span ( ) , * reason) ;
836
- continue ;
826
+ let removed = REMOVED_FEATURES . iter ( ) . find ( |f| name == f. name ) ;
827
+ let stable_removed = STABLE_REMOVED_FEATURES . iter ( ) . find ( |f| name == f. name ) ;
828
+ if let Some ( Feature { state, .. } ) = removed. or ( stable_removed) {
829
+ if let FeatureState :: Removed { reason }
830
+ | FeatureState :: Stabilized { reason } = state
831
+ {
832
+ feature_removed ( span_handler, mi. span ( ) , * reason) ;
833
+ continue ;
834
+ }
837
835
}
838
836
839
- if let Some ( ( _ , since, ..) ) = ACCEPTED_FEATURES . iter ( ) . find ( |f| name == f. 0 ) {
837
+ if let Some ( Feature { since, .. } ) = ACCEPTED_FEATURES . iter ( ) . find ( |f| name == f. name ) {
840
838
let since = Some ( Symbol :: intern ( since) ) ;
841
839
features. declared_lang_features . push ( ( name, mi. span ( ) , since) ) ;
842
840
continue ;
@@ -851,8 +849,8 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
851
849
}
852
850
}
853
851
854
- if let Some ( ( .. , set ) ) = ACTIVE_FEATURES . iter ( ) . find ( |f| name == f. 0 ) {
855
- set ( & mut features, mi. span ( ) ) ;
852
+ if let Some ( f ) = ACTIVE_FEATURES . iter ( ) . find ( |f| name == f. name ) {
853
+ f . set ( & mut features, mi. span ( ) ) ;
856
854
features. declared_lang_features . push ( ( name, mi. span ( ) , None ) ) ;
857
855
continue ;
858
856
}
@@ -864,6 +862,17 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
864
862
features
865
863
}
866
864
865
+ fn active_features_up_to ( edition : Edition ) -> impl Iterator < Item =& ' static Feature > {
866
+ ACTIVE_FEATURES . iter ( )
867
+ . filter ( move |feature| {
868
+ if let Some ( feature_edition) = feature. edition {
869
+ feature_edition <= edition
870
+ } else {
871
+ false
872
+ }
873
+ } )
874
+ }
875
+
867
876
pub fn check_crate ( krate : & ast:: Crate ,
868
877
sess : & ParseSess ,
869
878
features : & Features ,
0 commit comments