@@ -86,44 +86,38 @@ impl<'tcx> LibFeatureCollector<'tcx> {
86
86
}
87
87
88
88
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 ( ) ;
91
90
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 } ) ;
104
101
}
105
-
106
- self . lib_features . stable . insert ( feature, ( since, span) ) ;
107
102
}
108
- ( FeatureStability :: AcceptedSince ( _) , _ , true ) => {
103
+ ( FeatureStability :: AcceptedSince ( _) , Some ( ( FeatureStability :: Unstable , _ ) ) ) => {
109
104
self . tcx . sess . emit_err ( FeaturePreviouslyDeclared {
110
105
span,
111
106
feature,
112
107
declared : "stable" ,
113
108
prev_declared : "unstable" ,
114
109
} ) ;
115
110
}
116
- ( FeatureStability :: Unstable , false , _) => {
117
- self . lib_features . unstable . insert ( feature, span) ;
118
- }
119
- ( FeatureStability :: Unstable , true , _) => {
111
+ ( FeatureStability :: Unstable , Some ( ( FeatureStability :: AcceptedSince ( _) , _) ) ) => {
120
112
self . tcx . sess . emit_err ( FeaturePreviouslyDeclared {
121
113
span,
122
114
feature,
123
115
declared : "unstable" ,
124
116
prev_declared : "stable" ,
125
117
} ) ;
126
118
}
119
+ // duplicate `unstable` feature is ok.
120
+ ( FeatureStability :: Unstable , Some ( ( FeatureStability :: Unstable , _) ) ) => { }
127
121
}
128
122
}
129
123
}
0 commit comments