@@ -86,44 +86,38 @@ impl<'tcx> LibFeatureCollector<'tcx> {
8686 }
8787
8888 fn collect_feature ( & mut self , feature : Symbol , stability : FeatureStability , span : Span ) {
89- let already_in_stable = self . lib_features . stable . contains_key ( & feature) ;
90- let already_in_unstable = self . lib_features . unstable . contains_key ( & feature) ;
89+ let existing_stability = self . lib_features . stability . get ( & feature) . cloned ( ) ;
9190
92- match ( stability, already_in_stable, already_in_unstable) {
93- ( FeatureStability :: AcceptedSince ( since) , _, false ) => {
94- if let Some ( ( prev_since, _) ) = self . lib_features . stable . get ( & feature)
95- && * prev_since != since
96- {
97- self . tcx . sess . emit_err ( FeatureStableTwice {
98- span,
99- feature,
100- since,
101- prev_since : * prev_since,
102- } ) ;
103- return ;
91+ match ( stability, existing_stability) {
92+ ( _, None ) => {
93+ self . lib_features . stability . insert ( feature, ( stability, span) ) ;
94+ }
95+ (
96+ FeatureStability :: AcceptedSince ( since) ,
97+ Some ( ( FeatureStability :: AcceptedSince ( prev_since) , _) ) ,
98+ ) => {
99+ if prev_since != since {
100+ self . tcx . sess . emit_err ( FeatureStableTwice { span, feature, since, prev_since } ) ;
104101 }
105-
106- self . lib_features . stable . insert ( feature, ( since, span) ) ;
107102 }
108- ( FeatureStability :: AcceptedSince ( _) , _ , true ) => {
103+ ( FeatureStability :: AcceptedSince ( _) , Some ( ( FeatureStability :: Unstable , _ ) ) ) => {
109104 self . tcx . sess . emit_err ( FeaturePreviouslyDeclared {
110105 span,
111106 feature,
112107 declared : "stable" ,
113108 prev_declared : "unstable" ,
114109 } ) ;
115110 }
116- ( FeatureStability :: Unstable , false , _) => {
117- self . lib_features . unstable . insert ( feature, span) ;
118- }
119- ( FeatureStability :: Unstable , true , _) => {
111+ ( FeatureStability :: Unstable , Some ( ( FeatureStability :: AcceptedSince ( _) , _) ) ) => {
120112 self . tcx . sess . emit_err ( FeaturePreviouslyDeclared {
121113 span,
122114 feature,
123115 declared : "unstable" ,
124116 prev_declared : "stable" ,
125117 } ) ;
126118 }
119+ // duplicate `unstable` feature is ok.
120+ ( FeatureStability :: Unstable , Some ( ( FeatureStability :: Unstable , _) ) ) => { }
127121 }
128122 }
129123}
0 commit comments