@@ -39,12 +39,13 @@ use rustc::traits::{self, Reveal};
39
39
use rustc:: hir:: map as hir_map;
40
40
use util:: nodemap:: NodeSet ;
41
41
use lint:: { Level , LateContext , LintContext , LintArray , Lint } ;
42
- use lint:: { LintPass , LateLintPass } ;
42
+ use lint:: { LintPass , LateLintPass , EarlyLintPass , EarlyContext } ;
43
43
44
44
use std:: collections:: HashSet ;
45
45
46
46
use syntax:: ast;
47
47
use syntax:: attr;
48
+ use syntax:: feature_gate:: { AttributeGate , AttributeType , Stability , deprecated_attributes} ;
48
49
use syntax_pos:: Span ;
49
50
50
51
use rustc:: hir:: { self , PatKind } ;
@@ -741,6 +742,54 @@ impl LateLintPass for Deprecated {
741
742
}
742
743
}
743
744
745
+ declare_lint ! {
746
+ DEPRECATED_ATTR ,
747
+ Warn ,
748
+ "detects use of deprecated attributes"
749
+ }
750
+
751
+ /// Checks for use of attributes which have been deprecated.
752
+ #[ derive( Clone ) ]
753
+ pub struct DeprecatedAttr {
754
+ // This is not free to compute, so we want to keep it around, rather than
755
+ // compute it for every attribute.
756
+ depr_attrs : Vec < & ' static ( & ' static str , AttributeType , AttributeGate ) > ,
757
+ }
758
+
759
+ impl DeprecatedAttr {
760
+ pub fn new ( ) -> DeprecatedAttr {
761
+ DeprecatedAttr {
762
+ depr_attrs : deprecated_attributes ( ) ,
763
+ }
764
+ }
765
+ }
766
+
767
+ impl LintPass for DeprecatedAttr {
768
+ fn get_lints ( & self ) -> LintArray {
769
+ lint_array ! ( DEPRECATED_ATTR )
770
+ }
771
+ }
772
+
773
+ impl EarlyLintPass for DeprecatedAttr {
774
+ fn check_attribute ( & mut self , cx : & EarlyContext , attr : & ast:: Attribute ) {
775
+ let name = & * attr. name ( ) ;
776
+ for & & ( n, _, ref g) in & self . depr_attrs {
777
+ if n == name {
778
+ if let & AttributeGate :: Gated ( Stability :: Deprecated ( link) ,
779
+ ref name,
780
+ ref reason,
781
+ _) = g {
782
+ cx. span_lint ( DEPRECATED ,
783
+ attr. span ,
784
+ & format ! ( "use of deprecated attribute `{}`: {}. See {}" ,
785
+ name, reason, link) ) ;
786
+ }
787
+ return ;
788
+ }
789
+ }
790
+ }
791
+ }
792
+
744
793
declare_lint ! {
745
794
pub UNCONDITIONAL_RECURSION ,
746
795
Warn ,
0 commit comments