1212//! propagating default levels lexically from parent to children ast nodes.
1313
1414pub use self :: StabilityLevel :: * ;
15- use self :: AnnotationKind :: * ;
1615
1716use session:: Session ;
1817use lint;
@@ -52,11 +51,11 @@ impl StabilityLevel {
5251#[ derive( PartialEq ) ]
5352enum AnnotationKind {
5453 // Annotation is required if not inherited from unstable parents
55- AnnRequired ,
54+ Required ,
5655 // Annotation is useless, reject it
57- AnnProhibited ,
56+ Prohibited ,
5857 // Annotation itself is useless, but it can be propagated to children
59- AnnContainer ,
58+ Container ,
6059}
6160
6261/// A stability index, giving the stability level for items and methods.
@@ -91,8 +90,10 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
9190 if let Some ( mut stab) = attr:: find_stability ( self . tcx . sess . diagnostic ( ) ,
9291 attrs, item_sp) {
9392 // Error if prohibited, or can't inherit anything from a container
94- if kind == AnnProhibited ||
95- kind == AnnContainer && stab. level . is_stable ( ) && stab. depr . is_none ( ) {
93+ if kind == AnnotationKind :: Prohibited ||
94+ ( kind == AnnotationKind :: Container &&
95+ stab. level . is_stable ( ) &&
96+ stab. depr . is_none ( ) ) {
9697 self . tcx . sess . span_err ( item_sp, "This stability annotation is useless" ) ;
9798 }
9899
@@ -141,7 +142,7 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
141142 self . parent = parent;
142143 } else {
143144 debug ! ( "annotate: not found, parent = {:?}" , self . parent) ;
144- let mut is_error = kind == AnnRequired &&
145+ let mut is_error = kind == AnnotationKind :: Required &&
145146 self . export_map . contains ( & id) &&
146147 !self . tcx . sess . opts . test ;
147148 if let Some ( stab) = self . parent {
@@ -176,23 +177,23 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
176177 fn visit_item ( & mut self , i : & Item ) {
177178 let orig_in_trait_impl = self . in_trait_impl ;
178179 let orig_in_enum = self . in_enum ;
179- let mut kind = AnnRequired ;
180+ let mut kind = AnnotationKind :: Required ;
180181 match i. node {
181182 // Inherent impls and foreign modules serve only as containers for other items,
182183 // they don't have their own stability. They still can be annotated as unstable
183184 // and propagate this unstability to children, but this annotation is completely
184185 // optional. They inherit stability from their parents when unannotated.
185186 hir:: ItemImpl ( _, _, _, None , _, _) | hir:: ItemForeignMod ( ..) => {
186187 self . in_trait_impl = false ;
187- kind = AnnContainer ;
188+ kind = AnnotationKind :: Container ;
188189 }
189190 hir:: ItemImpl ( _, _, _, Some ( _) , _, _) => {
190191 self . in_trait_impl = true ;
191192 }
192193 hir:: ItemStruct ( ref sd, _) => {
193194 self . in_enum = false ;
194195 if !sd. is_struct ( ) {
195- self . annotate ( sd. id ( ) , & i. attrs , i. span , AnnRequired , |_| { } )
196+ self . annotate ( sd. id ( ) , & i. attrs , i. span , AnnotationKind :: Required , |_| { } )
196197 }
197198 }
198199 hir:: ItemEnum ( ..) => {
@@ -209,45 +210,49 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
209210 }
210211
211212 fn visit_trait_item ( & mut self , ti : & hir:: TraitItem ) {
212- self . annotate ( ti. id , & ti. attrs , ti. span , AnnRequired , |v| {
213+ self . annotate ( ti. id , & ti. attrs , ti. span , AnnotationKind :: Required , |v| {
213214 visit:: walk_trait_item ( v, ti) ;
214215 } ) ;
215216 }
216217
217218 fn visit_impl_item ( & mut self , ii : & hir:: ImplItem ) {
218- let kind = if self . in_trait_impl { AnnProhibited } else { AnnRequired } ;
219+ let kind = if self . in_trait_impl {
220+ AnnotationKind :: Prohibited
221+ } else {
222+ AnnotationKind :: Required
223+ } ;
219224 self . annotate ( ii. id , & ii. attrs , ii. span , kind, |v| {
220225 visit:: walk_impl_item ( v, ii) ;
221226 } ) ;
222227 }
223228
224229 fn visit_variant ( & mut self , var : & Variant , g : & ' v Generics , item_id : NodeId ) {
225- self . annotate ( var. node . data . id ( ) , & var. node . attrs , var. span , AnnRequired , |v| {
230+ self . annotate ( var. node . data . id ( ) , & var. node . attrs , var. span , AnnotationKind :: Required , |v| {
226231 visit:: walk_variant ( v, var, g, item_id) ;
227232 } )
228233 }
229234
230235 fn visit_struct_field ( & mut self , s : & StructField ) {
231236 // FIXME: This is temporary, can't use attributes with tuple variant fields until snapshot
232237 let kind = if self . in_enum && s. node . kind . is_unnamed ( ) {
233- AnnProhibited
238+ AnnotationKind :: Prohibited
234239 } else {
235- AnnRequired
240+ AnnotationKind :: Required
236241 } ;
237242 self . annotate ( s. node . id , & s. node . attrs , s. span , kind, |v| {
238243 visit:: walk_struct_field ( v, s) ;
239244 } ) ;
240245 }
241246
242247 fn visit_foreign_item ( & mut self , i : & hir:: ForeignItem ) {
243- self . annotate ( i. id , & i. attrs , i. span , AnnRequired , |v| {
248+ self . annotate ( i. id , & i. attrs , i. span , AnnotationKind :: Required , |v| {
244249 visit:: walk_foreign_item ( v, i) ;
245250 } ) ;
246251 }
247252
248253 fn visit_macro_def ( & mut self , md : & ' v hir:: MacroDef ) {
249254 if md. imported_from . is_none ( ) {
250- self . annotate ( md. id , & md. attrs , md. span , AnnRequired , |_| { } ) ;
255+ self . annotate ( md. id , & md. attrs , md. span , AnnotationKind :: Required , |_| { } ) ;
251256 }
252257 }
253258}
@@ -263,7 +268,7 @@ impl<'tcx> Index<'tcx> {
263268 in_trait_impl : false ,
264269 in_enum : false ,
265270 } ;
266- annotator. annotate ( ast:: CRATE_NODE_ID , & krate. attrs , krate. span , AnnRequired ,
271+ annotator. annotate ( ast:: CRATE_NODE_ID , & krate. attrs , krate. span , AnnotationKind :: Required ,
267272 |v| visit:: walk_crate ( v, krate) ) ;
268273 }
269274
0 commit comments