@@ -28,7 +28,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
28
28
use rustc_session:: lint;
29
29
use rustc_session:: lint:: builtin:: { DEPRECATED , INEFFECTIVE_UNSTABLE_TRAIT_IMPL } ;
30
30
use rustc_span:: { Span , Symbol , sym} ;
31
- use tracing:: { debug , info, instrument} ;
31
+ use tracing:: { info, instrument} ;
32
32
33
33
use crate :: errors;
34
34
@@ -326,43 +326,23 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
326
326
/// Determine the stability for a node based on its attributes and inherited stability. The
327
327
/// stability is recorded in the index and used as the parent. If the node is a function,
328
328
/// `fn_sig` is its signature.
329
- #[ instrument( level = "trace" , skip( self , visit_children) ) ]
330
- fn annotate < F > ( & mut self , def_id : LocalDefId , visit_children : F )
331
- where
332
- F : FnOnce ( & mut Self ) ,
333
- {
334
- let attrs = self . tcx . hir_attrs ( self . tcx . local_def_id_to_hir_id ( def_id) ) ;
335
- debug ! ( "annotate(id = {:?}, attrs = {:?})" , def_id, attrs) ;
336
-
337
- let stab = self . tcx . lookup_stability ( def_id) ;
338
-
329
+ #[ instrument( level = "trace" , skip( self ) ) ]
330
+ fn annotate ( & mut self , def_id : LocalDefId ) {
339
331
if !self . tcx . features ( ) . staged_api ( ) {
340
- visit_children ( self ) ;
341
332
return ;
342
333
}
343
334
344
- if let Some ( Stability {
345
- level : StabilityLevel :: Unstable { implied_by : Some ( implied_by) , .. } ,
346
- feature,
347
- } ) = stab
335
+ if let Some ( stability) = self . tcx . lookup_stability ( def_id)
336
+ && let StabilityLevel :: Unstable { implied_by : Some ( implied_by) , .. } = stability. level
348
337
{
349
- self . index . implications . insert ( implied_by, feature) ;
338
+ self . index . implications . insert ( implied_by, stability . feature ) ;
350
339
}
351
340
352
- // # Const stability
353
-
354
- let const_stab = self . tcx . lookup_const_stability ( def_id) ;
355
-
356
- if let Some ( ConstStability {
357
- level : StabilityLevel :: Unstable { implied_by : Some ( implied_by) , .. } ,
358
- feature,
359
- ..
360
- } ) = const_stab
341
+ if let Some ( stability) = self . tcx . lookup_const_stability ( def_id)
342
+ && let StabilityLevel :: Unstable { implied_by : Some ( implied_by) , .. } = stability. level
361
343
{
362
- self . index . implications . insert ( implied_by, feature) ;
344
+ self . index . implications . insert ( implied_by, stability . feature ) ;
363
345
}
364
-
365
- visit_children ( self )
366
346
}
367
347
}
368
348
@@ -380,53 +360,48 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
380
360
match i. kind {
381
361
hir:: ItemKind :: Struct ( _, _, ref sd) => {
382
362
if let Some ( ctor_def_id) = sd. ctor_def_id ( ) {
383
- self . annotate ( ctor_def_id, |_| { } )
363
+ self . annotate ( ctor_def_id) ;
384
364
}
385
365
}
386
366
_ => { }
387
367
}
388
368
389
- self . annotate ( i. owner_id . def_id , |v| intravisit:: walk_item ( v, i) ) ;
369
+ self . annotate ( i. owner_id . def_id ) ;
370
+ intravisit:: walk_item ( self , i)
390
371
}
391
372
392
373
fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem < ' tcx > ) {
393
- self . annotate ( ti. owner_id . def_id , |v| {
394
- intravisit:: walk_trait_item ( v, ti) ;
395
- } ) ;
374
+ self . annotate ( ti. owner_id . def_id ) ;
375
+ intravisit:: walk_trait_item ( self , ti) ;
396
376
}
397
377
398
378
fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
399
- self . annotate ( ii. owner_id . def_id , |v| {
400
- intravisit:: walk_impl_item ( v, ii) ;
401
- } ) ;
379
+ self . annotate ( ii. owner_id . def_id ) ;
380
+ intravisit:: walk_impl_item ( self , ii) ;
402
381
}
403
382
404
383
fn visit_variant ( & mut self , var : & ' tcx Variant < ' tcx > ) {
405
- self . annotate ( var. def_id , |v| {
406
- if let Some ( ctor_def_id) = var. data . ctor_def_id ( ) {
407
- v . annotate ( ctor_def_id, |_| { } ) ;
408
- }
384
+ self . annotate ( var. def_id ) ;
385
+ if let Some ( ctor_def_id) = var. data . ctor_def_id ( ) {
386
+ self . annotate ( ctor_def_id) ;
387
+ }
409
388
410
- intravisit:: walk_variant ( v, var)
411
- } )
389
+ intravisit:: walk_variant ( self , var)
412
390
}
413
391
414
392
fn visit_field_def ( & mut self , s : & ' tcx FieldDef < ' tcx > ) {
415
- self . annotate ( s. def_id , |v| {
416
- intravisit:: walk_field_def ( v, s) ;
417
- } ) ;
393
+ self . annotate ( s. def_id ) ;
394
+ intravisit:: walk_field_def ( self , s) ;
418
395
}
419
396
420
397
fn visit_foreign_item ( & mut self , i : & ' tcx hir:: ForeignItem < ' tcx > ) {
421
- self . annotate ( i. owner_id . def_id , |v| {
422
- intravisit:: walk_foreign_item ( v, i) ;
423
- } ) ;
398
+ self . annotate ( i. owner_id . def_id ) ;
399
+ intravisit:: walk_foreign_item ( self , i) ;
424
400
}
425
401
426
402
fn visit_generic_param ( & mut self , p : & ' tcx hir:: GenericParam < ' tcx > ) {
427
- self . annotate ( p. def_id , |v| {
428
- intravisit:: walk_generic_param ( v, p) ;
429
- } ) ;
403
+ self . annotate ( p. def_id ) ;
404
+ intravisit:: walk_generic_param ( self , p) ;
430
405
}
431
406
}
432
407
@@ -637,12 +612,9 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
637
612
638
613
fn stability_index ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> Index {
639
614
let mut index = Index { implications : Default :: default ( ) } ;
640
-
641
- {
642
- let mut annotator = Annotator { tcx, index : & mut index } ;
643
-
644
- annotator. annotate ( CRATE_DEF_ID , |v| tcx. hir_walk_toplevel_module ( v) ) ;
645
- }
615
+ let mut annotator = Annotator { tcx, index : & mut index } ;
616
+ annotator. annotate ( CRATE_DEF_ID ) ;
617
+ tcx. hir_walk_toplevel_module ( & mut annotator) ;
646
618
index
647
619
}
648
620
0 commit comments