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