@@ -268,93 +268,51 @@ fn lookup_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ConstSt
268268 None
269269}
270270
271- /// A private tree-walker for producing an `Index`.
272- struct Annotator < ' tcx > {
273- tcx : TyCtxt < ' tcx > ,
274- implications : UnordMap < Symbol , Symbol > ,
275- }
276-
277- impl < ' tcx > Annotator < ' tcx > {
278- /// Determine the stability for a node based on its attributes and inherited stability. The
279- /// stability is recorded in the index and used as the parent. If the node is a function,
280- /// `fn_sig` is its signature.
281- #[ instrument( level = "trace" , skip( self ) ) ]
282- fn annotate ( & mut self , def_id : LocalDefId ) {
283- if !self . tcx . features ( ) . staged_api ( ) {
284- return ;
285- }
271+ fn stability_implications ( tcx : TyCtxt < ' _ > , LocalCrate : LocalCrate ) -> UnordMap < Symbol , Symbol > {
272+ let mut implications = UnordMap :: default ( ) ;
286273
287- if let Some ( stability) = self . tcx . lookup_stability ( def_id)
274+ let mut register_implication = |def_id| {
275+ if let Some ( stability) = tcx. lookup_stability ( def_id)
288276 && let StabilityLevel :: Unstable { implied_by : Some ( implied_by) , .. } = stability. level
289277 {
290- self . implications . insert ( implied_by, stability. feature ) ;
278+ implications. insert ( implied_by, stability. feature ) ;
291279 }
292280
293- if let Some ( stability) = self . tcx . lookup_const_stability ( def_id)
281+ if let Some ( stability) = tcx. lookup_const_stability ( def_id)
294282 && let StabilityLevel :: Unstable { implied_by : Some ( implied_by) , .. } = stability. level
295283 {
296- self . implications . insert ( implied_by, stability. feature ) ;
284+ implications. insert ( implied_by, stability. feature ) ;
297285 }
298- }
299- }
300-
301- impl < ' tcx > Visitor < ' tcx > for Annotator < ' tcx > {
302- /// Because stability levels are scoped lexically, we want to walk
303- /// nested items in the context of the outer item, so enable
304- /// deep-walking.
305- type NestedFilter = nested_filter:: All ;
306-
307- fn maybe_tcx ( & mut self ) -> Self :: MaybeTyCtxt {
308- self . tcx
309- }
286+ } ;
310287
311- fn visit_item ( & mut self , i : & ' tcx Item < ' tcx > ) {
312- match i. kind {
313- hir:: ItemKind :: Struct ( _, _, ref sd) => {
314- if let Some ( ctor_def_id) = sd. ctor_def_id ( ) {
315- self . annotate ( ctor_def_id) ;
288+ if tcx. features ( ) . staged_api ( ) {
289+ register_implication ( CRATE_DEF_ID ) ;
290+ for def_id in tcx. hir_crate_items ( ( ) ) . definitions ( ) {
291+ register_implication ( def_id) ;
292+ let def_kind = tcx. def_kind ( def_id) ;
293+ if def_kind. is_adt ( ) {
294+ let adt = tcx. adt_def ( def_id) ;
295+ for variant in adt. variants ( ) {
296+ if variant. def_id != def_id. to_def_id ( ) {
297+ register_implication ( variant. def_id . expect_local ( ) ) ;
298+ }
299+ for field in & variant. fields {
300+ register_implication ( field. did . expect_local ( ) ) ;
301+ }
302+ if let Some ( ctor_def_id) = variant. ctor_def_id ( ) {
303+ register_implication ( ctor_def_id. expect_local ( ) )
304+ }
305+ }
306+ }
307+ if def_kind. has_generics ( ) {
308+ for param in tcx. generics_of ( def_id) . own_params . iter ( ) {
309+ register_implication ( param. def_id . expect_local ( ) )
316310 }
317311 }
318- _ => { }
319- }
320-
321- self . annotate ( i. owner_id . def_id ) ;
322- intravisit:: walk_item ( self , i)
323- }
324-
325- fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem < ' tcx > ) {
326- self . annotate ( ti. owner_id . def_id ) ;
327- intravisit:: walk_trait_item ( self , ti) ;
328- }
329-
330- fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
331- self . annotate ( ii. owner_id . def_id ) ;
332- intravisit:: walk_impl_item ( self , ii) ;
333- }
334-
335- fn visit_variant ( & mut self , var : & ' tcx Variant < ' tcx > ) {
336- self . annotate ( var. def_id ) ;
337- if let Some ( ctor_def_id) = var. data . ctor_def_id ( ) {
338- self . annotate ( ctor_def_id) ;
339312 }
340-
341- intravisit:: walk_variant ( self , var)
342313 }
343314
344- fn visit_field_def ( & mut self , s : & ' tcx FieldDef < ' tcx > ) {
345- self . annotate ( s. def_id ) ;
346- intravisit:: walk_field_def ( self , s) ;
347- }
348-
349- fn visit_foreign_item ( & mut self , i : & ' tcx hir:: ForeignItem < ' tcx > ) {
350- self . annotate ( i. owner_id . def_id ) ;
351- intravisit:: walk_foreign_item ( self , i) ;
352- }
353-
354- fn visit_generic_param ( & mut self , p : & ' tcx hir:: GenericParam < ' tcx > ) {
355- self . annotate ( p. def_id ) ;
356- intravisit:: walk_generic_param ( self , p) ;
357- }
315+ implications
358316}
359317
360318struct MissingStabilityAnnotations < ' tcx > {
@@ -566,13 +524,6 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
566524 }
567525}
568526
569- fn stability_implications ( tcx : TyCtxt < ' _ > , LocalCrate : LocalCrate ) -> UnordMap < Symbol , Symbol > {
570- let mut annotator = Annotator { tcx, implications : Default :: default ( ) } ;
571- annotator. annotate ( CRATE_DEF_ID ) ;
572- tcx. hir_walk_toplevel_module ( & mut annotator) ;
573- annotator. implications
574- }
575-
576527/// Cross-references the feature names of unstable APIs with enabled
577528/// features and possibly prints errors.
578529fn check_mod_unstable_api_usage ( tcx : TyCtxt < ' _ > , module_def_id : LocalModDefId ) {
0 commit comments