@@ -39,12 +39,13 @@ use rustc::traits::{self, Reveal};
3939use rustc:: hir:: map as hir_map;
4040use util:: nodemap:: NodeSet ;
4141use lint:: { Level , LateContext , LintContext , LintArray , Lint } ;
42- use lint:: { LintPass , LateLintPass } ;
42+ use lint:: { LintPass , LateLintPass , EarlyLintPass , EarlyContext } ;
4343
4444use std:: collections:: HashSet ;
4545
4646use syntax:: ast;
4747use syntax:: attr;
48+ use syntax:: feature_gate:: { AttributeGate , AttributeType , Stability , deprecated_attributes} ;
4849use syntax_pos:: Span ;
4950
5051use rustc:: hir:: { self , PatKind } ;
@@ -741,6 +742,54 @@ impl LateLintPass for Deprecated {
741742 }
742743}
743744
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+
744793declare_lint ! {
745794 pub UNCONDITIONAL_RECURSION ,
746795 Warn ,
0 commit comments