Skip to content

Commit 121e903

Browse files
committed
Add possibility of deprecating attributes
1 parent 3a25b65 commit 121e903

File tree

4 files changed

+129
-47
lines changed

4 files changed

+129
-47
lines changed

src/librustc/lint/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,5 +314,4 @@ pub enum LintSource {
314314
pub type LevelSource = (Level, LintSource);
315315

316316
pub mod builtin;
317-
318317
mod context;

src/librustc_lint/builtin.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ use rustc::traits::{self, Reveal};
3939
use rustc::hir::map as hir_map;
4040
use util::nodemap::NodeSet;
4141
use lint::{Level, LateContext, LintContext, LintArray, Lint};
42-
use lint::{LintPass, LateLintPass};
42+
use lint::{LintPass, LateLintPass, EarlyLintPass, EarlyContext};
4343

4444
use std::collections::HashSet;
4545

46-
use syntax::ast;
46+
use syntax::{ast, feature_gate};
4747
use syntax::attr;
4848
use syntax_pos::Span;
4949

@@ -741,6 +741,40 @@ impl LateLintPass for Deprecated {
741741
}
742742
}
743743

744+
declare_lint! {
745+
DEPRECATED_ATTR,
746+
Warn,
747+
"detects use of deprecated attributes"
748+
}
749+
750+
/// Checks for use of attributes which have been deprecated.
751+
#[derive(Clone)]
752+
pub struct DeprecatedAttr;
753+
754+
impl LintPass for DeprecatedAttr {
755+
fn get_lints(&self) -> LintArray {
756+
lint_array!(DEPRECATED_ATTR)
757+
}
758+
}
759+
760+
impl EarlyLintPass for DeprecatedAttr {
761+
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
762+
let name = &*attr.name();
763+
for &(n, _, ref g) in feature_gate::KNOWN_ATTRIBUTES {
764+
if n == name {
765+
if let &feature_gate::AttributeGate::Gated(feature_gate::Stability::Deprecated,
766+
ref name,
767+
..) = g {
768+
cx.span_lint(DEPRECATED,
769+
attr.span,
770+
&format!("use of deprecated attribute: {}", name));
771+
}
772+
return;
773+
}
774+
}
775+
}
776+
}
777+
744778
declare_lint! {
745779
pub UNCONDITIONAL_RECURSION,
746780
Warn,

src/librustc_lint/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
103103

104104
add_early_builtin!(sess,
105105
UnusedParens,
106+
DeprecatedAttr,
106107
);
107108

108109
add_builtin!(sess,

0 commit comments

Comments
 (0)