Skip to content

Commit 46d39f3

Browse files
authored
Auto merge of #37128 - nrc:depr-attr, r=@alexcrichton
Deprecate no_debug and custom_derive r? @nikomatsakis
2 parents bc283c9 + 8c4a39c commit 46d39f3

File tree

8 files changed

+199
-51
lines changed

8 files changed

+199
-51
lines changed

src/librustc/lint/mod.rs

-1
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

+50-1
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ 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

4646
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};
@@ -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+
744793
declare_lint! {
745794
pub UNCONDITIONAL_RECURSION,
746795
Warn,

src/librustc_lint/lib.rs

+13
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)),*]);
@@ -105,6 +114,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
105114
UnusedParens,
106115
);
107116

117+
add_early_builtin_with_new!(sess,
118+
DeprecatedAttr,
119+
);
120+
108121
add_builtin!(sess,
109122
HardwiredLints,
110123
WhileTrue,

src/libsyntax/feature_gate.rs

+116-48
Large diffs are not rendered by default.

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/libsyntax_ext/deriving/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
175175
feature_gate::GateIssue::Language,
176176
feature_gate::EXPLAIN_CUSTOM_DERIVE);
177177
} else {
178+
cx.span_warn(titem.span, feature_gate::EXPLAIN_DEPR_CUSTOM_DERIVE);
178179
let name = intern_and_get_ident(&format!("derive_{}", tname));
179180
let mitem = cx.meta_word(titem.span, name);
180181
new_attributes.push(cx.attribute(mitem.span, mitem));

src/test/compile-fail/deriving-meta-unknown-trait.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-tidy-linelength
12+
1113
#[derive(Eqr)]
12-
//~^ ERROR `#[derive]` for custom traits is not stable enough for use and is subject to change
14+
//~^ ERROR `#[derive]` for custom traits is not stable enough for use. It is deprecated and will be removed in v1.15 (see issue #29644)
1315
struct Foo;
1416

1517
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![deny(deprecated)]
12+
#![feature(no_debug)]
13+
14+
#[no_debug] //~ ERROR use of deprecated attribute `no_debug`
15+
fn main() {}

0 commit comments

Comments
 (0)