review changes
This commit is contained in:
parent
9322332140
commit
8c4a39cd95
5 changed files with 60 additions and 17 deletions
|
@ -43,8 +43,9 @@ use lint::{LintPass, LateLintPass, EarlyLintPass, EarlyContext};
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use syntax::{ast, feature_gate};
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
|
use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_attributes};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
use rustc::hir::{self, PatKind};
|
use rustc::hir::{self, PatKind};
|
||||||
|
@ -749,7 +750,19 @@ declare_lint! {
|
||||||
|
|
||||||
/// Checks for use of attributes which have been deprecated.
|
/// Checks for use of attributes which have been deprecated.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DeprecatedAttr;
|
pub struct DeprecatedAttr {
|
||||||
|
// This is not free to compute, so we want to keep it around, rather than
|
||||||
|
// compute it for every attribute.
|
||||||
|
depr_attrs: Vec<&'static (&'static str, AttributeType, AttributeGate)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DeprecatedAttr {
|
||||||
|
pub fn new() -> DeprecatedAttr {
|
||||||
|
DeprecatedAttr {
|
||||||
|
depr_attrs: deprecated_attributes(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl LintPass for DeprecatedAttr {
|
impl LintPass for DeprecatedAttr {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
|
@ -760,14 +773,16 @@ impl LintPass for DeprecatedAttr {
|
||||||
impl EarlyLintPass for DeprecatedAttr {
|
impl EarlyLintPass for DeprecatedAttr {
|
||||||
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
|
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
|
||||||
let name = &*attr.name();
|
let name = &*attr.name();
|
||||||
for &(n, _, ref g) in feature_gate::KNOWN_ATTRIBUTES {
|
for &&(n, _, ref g) in &self.depr_attrs {
|
||||||
if n == name {
|
if n == name {
|
||||||
if let &feature_gate::AttributeGate::Gated(feature_gate::Stability::Deprecated,
|
if let &AttributeGate::Gated(Stability::Deprecated(link),
|
||||||
ref name,
|
ref name,
|
||||||
..) = g {
|
ref reason,
|
||||||
|
_) = g {
|
||||||
cx.span_lint(DEPRECATED,
|
cx.span_lint(DEPRECATED,
|
||||||
attr.span,
|
attr.span,
|
||||||
&format!("use of deprecated attribute: {}", name));
|
&format!("use of deprecated attribute `{}`: {}. See {}",
|
||||||
|
name, reason, link));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#![feature(rustc_private)]
|
#![feature(rustc_private)]
|
||||||
#![feature(slice_patterns)]
|
#![feature(slice_patterns)]
|
||||||
#![feature(staged_api)]
|
#![feature(staged_api)]
|
||||||
|
#![feature(dotdot_in_tuple_patterns)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
|
@ -95,6 +96,14 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! add_early_builtin_with_new {
|
||||||
|
($sess:ident, $($name:ident),*,) => (
|
||||||
|
{$(
|
||||||
|
store.register_early_pass($sess, false, box $name::new());
|
||||||
|
)*}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! add_lint_group {
|
macro_rules! add_lint_group {
|
||||||
($sess:ident, $name:expr, $($lint:ident),*) => (
|
($sess:ident, $name:expr, $($lint:ident),*) => (
|
||||||
store.register_group($sess, false, $name, vec![$(LintId::of($lint)),*]);
|
store.register_group($sess, false, $name, vec![$(LintId::of($lint)),*]);
|
||||||
|
@ -103,6 +112,9 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
|
||||||
|
|
||||||
add_early_builtin!(sess,
|
add_early_builtin!(sess,
|
||||||
UnusedParens,
|
UnusedParens,
|
||||||
|
);
|
||||||
|
|
||||||
|
add_early_builtin_with_new!(sess,
|
||||||
DeprecatedAttr,
|
DeprecatedAttr,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -377,17 +377,28 @@ pub enum AttributeGate {
|
||||||
Ungated,
|
Ungated,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
impl AttributeGate {
|
||||||
|
fn is_deprecated(&self) -> bool {
|
||||||
|
match *self {
|
||||||
|
Gated(Stability::Deprecated(_), ..) => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||||
pub enum Stability {
|
pub enum Stability {
|
||||||
Unstable,
|
Unstable,
|
||||||
Deprecated,
|
// Argument is tracking issue link.
|
||||||
|
Deprecated(&'static str),
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn() is not Debug
|
// fn() is not Debug
|
||||||
impl ::std::fmt::Debug for AttributeGate {
|
impl ::std::fmt::Debug for AttributeGate {
|
||||||
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Gated(_, ref name, ref expl, _) => write!(fmt, "Gated({}, {})", name, expl),
|
Gated(ref stab, ref name, ref expl, _) =>
|
||||||
|
write!(fmt, "Gated({:?}, {}, {})", stab, name, expl),
|
||||||
Ungated => write!(fmt, "Ungated")
|
Ungated => write!(fmt, "Ungated")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -402,6 +413,10 @@ macro_rules! cfg_fn {
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn deprecated_attributes() -> Vec<&'static (&'static str, AttributeType, AttributeGate)> {
|
||||||
|
KNOWN_ATTRIBUTES.iter().filter(|a| a.2.is_deprecated()).collect()
|
||||||
|
}
|
||||||
|
|
||||||
// Attributes that have a special meaning to rustc or rustdoc
|
// Attributes that have a special meaning to rustc or rustdoc
|
||||||
pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeGate)] = &[
|
pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeGate)] = &[
|
||||||
// Normal attributes
|
// Normal attributes
|
||||||
|
@ -643,10 +658,10 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeGat
|
||||||
("link_section", Whitelisted, Ungated),
|
("link_section", Whitelisted, Ungated),
|
||||||
("no_builtins", Whitelisted, Ungated),
|
("no_builtins", Whitelisted, Ungated),
|
||||||
("no_mangle", Whitelisted, Ungated),
|
("no_mangle", Whitelisted, Ungated),
|
||||||
("no_debug", Whitelisted, Gated(Stability::Deprecated,
|
("no_debug", Whitelisted, Gated(
|
||||||
|
Stability::Deprecated("https://github.com/rust-lang/rust/issues/29721"),
|
||||||
"no_debug",
|
"no_debug",
|
||||||
"the `#[no_debug]` attribute \
|
"the `#[no_debug]` attribute is an experimental feature",
|
||||||
is an experimental feature",
|
|
||||||
cfg_fn!(no_debug))),
|
cfg_fn!(no_debug))),
|
||||||
("omit_gdb_pretty_printer_section", Whitelisted, Gated(Stability::Unstable,
|
("omit_gdb_pretty_printer_section", Whitelisted, Gated(Stability::Unstable,
|
||||||
"omit_gdb_pretty_printer_section",
|
"omit_gdb_pretty_printer_section",
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#![cfg_attr(stage0, feature(question_mark))]
|
#![cfg_attr(stage0, feature(question_mark))]
|
||||||
#![feature(rustc_diagnostic_macros)]
|
#![feature(rustc_diagnostic_macros)]
|
||||||
#![feature(specialization)]
|
#![feature(specialization)]
|
||||||
|
#![feature(dotdot_in_tuple_patterns)]
|
||||||
|
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
extern crate term;
|
extern crate term;
|
||||||
|
|
|
@ -11,5 +11,5 @@
|
||||||
#![deny(deprecated)]
|
#![deny(deprecated)]
|
||||||
#![feature(no_debug)]
|
#![feature(no_debug)]
|
||||||
|
|
||||||
#[no_debug] //~ ERROR use of deprecated attribute: no_debug
|
#[no_debug] //~ ERROR use of deprecated attribute `no_debug`
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue