Skip to content

Commit 8c4a39c

Browse files
committed
review changes
1 parent 9322332 commit 8c4a39c

File tree

5 files changed

+60
-17
lines changed

5 files changed

+60
-17
lines changed

src/librustc_lint/builtin.rs

+22-7
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ use lint::{LintPass, LateLintPass, EarlyLintPass, EarlyContext};
4343

4444
use std::collections::HashSet;
4545

46-
use syntax::{ast, feature_gate};
46+
use syntax::ast;
4747
use syntax::attr;
48+
use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_attributes};
4849
use syntax_pos::Span;
4950

5051
use rustc::hir::{self, PatKind};
@@ -749,7 +750,19 @@ declare_lint! {
749750

750751
/// Checks for use of attributes which have been deprecated.
751752
#[derive(Clone)]
752-
pub struct DeprecatedAttr;
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+
}
753766

754767
impl LintPass for DeprecatedAttr {
755768
fn get_lints(&self) -> LintArray {
@@ -760,14 +773,16 @@ impl LintPass for DeprecatedAttr {
760773
impl EarlyLintPass for DeprecatedAttr {
761774
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
762775
let name = &*attr.name();
763-
for &(n, _, ref g) in feature_gate::KNOWN_ATTRIBUTES {
776+
for &&(n, _, ref g) in &self.depr_attrs {
764777
if n == name {
765-
if let &feature_gate::AttributeGate::Gated(feature_gate::Stability::Deprecated,
766-
ref name,
767-
..) = g {
778+
if let &AttributeGate::Gated(Stability::Deprecated(link),
779+
ref name,
780+
ref reason,
781+
_) = g {
768782
cx.span_lint(DEPRECATED,
769783
attr.span,
770-
&format!("use of deprecated attribute: {}", name));
784+
&format!("use of deprecated attribute `{}`: {}. See {}",
785+
name, reason, link));
771786
}
772787
return;
773788
}

src/librustc_lint/lib.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#![feature(rustc_private)]
3838
#![feature(slice_patterns)]
3939
#![feature(staged_api)]
40+
#![feature(dotdot_in_tuple_patterns)]
4041

4142
#[macro_use]
4243
extern crate syntax;
@@ -95,6 +96,14 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
9596
)
9697
}
9798

99+
macro_rules! add_early_builtin_with_new {
100+
($sess:ident, $($name:ident),*,) => (
101+
{$(
102+
store.register_early_pass($sess, false, box $name::new());
103+
)*}
104+
)
105+
}
106+
98107
macro_rules! add_lint_group {
99108
($sess:ident, $name:expr, $($lint:ident),*) => (
100109
store.register_group($sess, false, $name, vec![$(LintId::of($lint)),*]);
@@ -103,9 +112,12 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
103112

104113
add_early_builtin!(sess,
105114
UnusedParens,
106-
DeprecatedAttr,
107115
);
108116

117+
add_early_builtin_with_new!(sess,
118+
DeprecatedAttr,
119+
);
120+
109121
add_builtin!(sess,
110122
HardwiredLints,
111123
WhileTrue,

src/libsyntax/feature_gate.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -377,17 +377,28 @@ pub enum AttributeGate {
377377
Ungated,
378378
}
379379

380-
#[derive(Copy, Clone, PartialEq, Eq)]
380+
impl AttributeGate {
381+
fn is_deprecated(&self) -> bool {
382+
match *self {
383+
Gated(Stability::Deprecated(_), ..) => true,
384+
_ => false,
385+
}
386+
}
387+
}
388+
389+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
381390
pub enum Stability {
382391
Unstable,
383-
Deprecated,
392+
// Argument is tracking issue link.
393+
Deprecated(&'static str),
384394
}
385395

386396
// fn() is not Debug
387397
impl ::std::fmt::Debug for AttributeGate {
388398
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
389399
match *self {
390-
Gated(_, ref name, ref expl, _) => write!(fmt, "Gated({}, {})", name, expl),
400+
Gated(ref stab, ref name, ref expl, _) =>
401+
write!(fmt, "Gated({:?}, {}, {})", stab, name, expl),
391402
Ungated => write!(fmt, "Ungated")
392403
}
393404
}
@@ -402,6 +413,10 @@ macro_rules! cfg_fn {
402413
}}
403414
}
404415

416+
pub fn deprecated_attributes() -> Vec<&'static (&'static str, AttributeType, AttributeGate)> {
417+
KNOWN_ATTRIBUTES.iter().filter(|a| a.2.is_deprecated()).collect()
418+
}
419+
405420
// Attributes that have a special meaning to rustc or rustdoc
406421
pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeGate)] = &[
407422
// Normal attributes
@@ -643,11 +658,11 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeGat
643658
("link_section", Whitelisted, Ungated),
644659
("no_builtins", Whitelisted, Ungated),
645660
("no_mangle", Whitelisted, Ungated),
646-
("no_debug", Whitelisted, Gated(Stability::Deprecated,
647-
"no_debug",
648-
"the `#[no_debug]` attribute \
649-
is an experimental feature",
650-
cfg_fn!(no_debug))),
661+
("no_debug", Whitelisted, Gated(
662+
Stability::Deprecated("https://github.com/rust-lang/rust/issues/29721"),
663+
"no_debug",
664+
"the `#[no_debug]` attribute is an experimental feature",
665+
cfg_fn!(no_debug))),
651666
("omit_gdb_pretty_printer_section", Whitelisted, Gated(Stability::Unstable,
652667
"omit_gdb_pretty_printer_section",
653668
"the `#[omit_gdb_pretty_printer_section]` \

src/libsyntax/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#![cfg_attr(stage0, feature(question_mark))]
3535
#![feature(rustc_diagnostic_macros)]
3636
#![feature(specialization)]
37+
#![feature(dotdot_in_tuple_patterns)]
3738

3839
extern crate serialize;
3940
extern crate term;

src/test/compile-fail/feature-gate-no-debug-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
#![deny(deprecated)]
1212
#![feature(no_debug)]
1313

14-
#[no_debug] //~ ERROR use of deprecated attribute: no_debug
14+
#[no_debug] //~ ERROR use of deprecated attribute `no_debug`
1515
fn main() {}

0 commit comments

Comments
 (0)