1- use super :: active:: { ACTIVE_FEATURES , Features } ;
1+ use super :: { active:: { ACTIVE_FEATURES , Features } , Feature , State as FeatureState } ;
22use super :: accepted:: ACCEPTED_FEATURES ;
33use super :: removed:: { REMOVED_FEATURES , STABLE_REMOVED_FEATURES } ;
44use super :: builtin_attrs:: { AttributeGate , AttributeType , BuiltinAttribute , BUILTIN_ATTRIBUTE_MAP } ;
@@ -127,17 +127,16 @@ pub fn check_attribute(attr: &ast::Attribute, parse_sess: &ParseSess, features:
127127}
128128
129129fn 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) {
132131 // 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
135134 } else {
136135 // search in Accepted, Removed, or Stable Removed features
137136 let found = ACCEPTED_FEATURES . iter ( ) . chain ( REMOVED_FEATURES ) . chain ( STABLE_REMOVED_FEATURES )
138- . find ( |t| t. 0 == feature) ;
137+ . find ( |t| t. name == feature) ;
139138 match found {
140- Some ( & ( _ , _ , issue, _ ) ) => issue,
139+ Some ( & Feature { issue, .. } ) => issue,
141140 None => panic ! ( "Feature `{}` is not declared anywhere" , feature) ,
142141 }
143142 }
@@ -733,14 +732,11 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
733732 }
734733 }
735734
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+ } ) ;
744740
745741 // Process the edition umbrella feature-gates first, to ensure
746742 // `edition_enabled_features` is completed before it's queried.
@@ -761,21 +757,19 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
761757
762758 let name = mi. name_or_empty ( ) ;
763759
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 {
766762 continue ;
767763 }
768764
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+ } ) ;
779773 }
780774 }
781775 }
@@ -829,14 +823,18 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
829823 continue ;
830824 }
831825
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+ }
837835 }
838836
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 ) {
840838 let since = Some ( Symbol :: intern ( since) ) ;
841839 features. declared_lang_features . push ( ( name, mi. span ( ) , since) ) ;
842840 continue ;
@@ -851,8 +849,8 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
851849 }
852850 }
853851
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 ( ) ) ;
856854 features. declared_lang_features . push ( ( name, mi. span ( ) , None ) ) ;
857855 continue ;
858856 }
@@ -864,6 +862,17 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
864862 features
865863}
866864
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+
867876pub fn check_crate ( krate : & ast:: Crate ,
868877 sess : & ParseSess ,
869878 features : & Features ,
0 commit comments