@@ -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 , Stability , with_deprecated_attributes} ;
48
49
use syntax_pos:: Span ;
49
50
50
51
use rustc:: hir:: { self , PatKind } ;
@@ -741,6 +742,45 @@ 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
+
755
+ impl LintPass for DeprecatedAttr {
756
+ fn get_lints ( & self ) -> LintArray {
757
+ lint_array ! ( DEPRECATED_ATTR )
758
+ }
759
+ }
760
+
761
+ impl EarlyLintPass for DeprecatedAttr {
762
+ fn check_attribute ( & mut self , cx : & EarlyContext , attr : & ast:: Attribute ) {
763
+ let name = & * attr. name ( ) ;
764
+ with_deprecated_attributes ( |depr_attrs| {
765
+ for & & ( n, _, ref g) in depr_attrs {
766
+ if n == name {
767
+ if let & AttributeGate :: Gated ( Stability :: Deprecated ( link) ,
768
+ ref name,
769
+ ref reason,
770
+ _) = g {
771
+ cx. span_lint ( DEPRECATED ,
772
+ attr. span ,
773
+ & format ! ( "use of deprecated attribute `{}`: {}. See {}" ,
774
+ name, reason, link) ) ;
775
+ }
776
+ // Returns from the closure, skipping the rest of the loop.
777
+ return ;
778
+ }
779
+ }
780
+ } )
781
+ }
782
+ }
783
+
744
784
declare_lint ! {
745
785
pub UNCONDITIONAL_RECURSION ,
746
786
Warn ,
0 commit comments