@@ -567,10 +567,21 @@ declare_lint! {
567
567
}
568
568
569
569
/// Checks for use of items with `#[deprecated]` or `#[rustc_deprecated]` attributes
570
- #[ derive( Copy , Clone ) ]
571
- pub struct Deprecated ;
570
+ #[ derive( Clone ) ]
571
+ pub struct Deprecated {
572
+ /// Tracks the `NodeId` of the current item.
573
+ ///
574
+ /// This is required since not all node ids are present in the hir map.
575
+ current_item : ast:: NodeId ,
576
+ }
572
577
573
578
impl Deprecated {
579
+ pub fn new ( ) -> Deprecated {
580
+ Deprecated {
581
+ current_item : ast:: CRATE_NODE_ID ,
582
+ }
583
+ }
584
+
574
585
fn lint ( & self , cx : & LateContext , _id : DefId , span : Span ,
575
586
stability : & Option < & attr:: Stability > , deprecation : & Option < attr:: Deprecation > ) {
576
587
// Deprecated attributes apply in-crate and cross-crate.
@@ -591,6 +602,19 @@ impl Deprecated {
591
602
cx. span_lint ( lint, span, & msg) ;
592
603
}
593
604
}
605
+
606
+ fn push_item ( & mut self , item_id : ast:: NodeId ) {
607
+ self . current_item = item_id;
608
+ }
609
+
610
+ fn item_post ( & mut self , cx : & LateContext , item_id : ast:: NodeId ) {
611
+ assert_eq ! ( self . current_item, item_id) ;
612
+ self . current_item = cx. tcx . map . get_parent ( item_id) ;
613
+ }
614
+
615
+ fn parent_def ( & self , cx : & LateContext ) -> DefId {
616
+ cx. tcx . map . local_def_id ( self . current_item )
617
+ }
594
618
}
595
619
596
620
impl LintPass for Deprecated {
@@ -601,11 +625,16 @@ impl LintPass for Deprecated {
601
625
602
626
impl LateLintPass for Deprecated {
603
627
fn check_item ( & mut self , cx : & LateContext , item : & hir:: Item ) {
628
+ self . push_item ( item. id ) ;
604
629
stability:: check_item ( cx. tcx , item, false ,
605
630
& mut |id, sp, stab, depr|
606
631
self . lint ( cx, id, sp, & stab, & depr) ) ;
607
632
}
608
633
634
+ fn check_item_post ( & mut self , cx : & LateContext , item : & hir:: Item ) {
635
+ self . item_post ( cx, item. id ) ;
636
+ }
637
+
609
638
fn check_expr ( & mut self , cx : & LateContext , e : & hir:: Expr ) {
610
639
stability:: check_expr ( cx. tcx , e,
611
640
& mut |id, sp, stab, depr|
@@ -629,6 +658,30 @@ impl LateLintPass for Deprecated {
629
658
& mut |id, sp, stab, depr|
630
659
self . lint ( cx, id, sp, & stab, & depr) ) ;
631
660
}
661
+
662
+ fn check_impl_item ( & mut self , _: & LateContext , item : & hir:: ImplItem ) {
663
+ self . push_item ( item. id ) ;
664
+ }
665
+
666
+ fn check_impl_item_post ( & mut self , cx : & LateContext , item : & hir:: ImplItem ) {
667
+ self . item_post ( cx, item. id ) ;
668
+ }
669
+
670
+ fn check_trait_item ( & mut self , _: & LateContext , item : & hir:: TraitItem ) {
671
+ self . push_item ( item. id ) ;
672
+ }
673
+
674
+ fn check_trait_item_post ( & mut self , cx : & LateContext , item : & hir:: TraitItem ) {
675
+ self . item_post ( cx, item. id ) ;
676
+ }
677
+
678
+ fn check_foreign_item ( & mut self , _: & LateContext , item : & hir:: ForeignItem ) {
679
+ self . push_item ( item. id ) ;
680
+ }
681
+
682
+ fn check_foreign_item_post ( & mut self , cx : & LateContext , item : & hir:: ForeignItem ) {
683
+ self . item_post ( cx, item. id ) ;
684
+ }
632
685
}
633
686
634
687
declare_lint ! {
0 commit comments