Skip to content

Commit 98cb0c3

Browse files
authored
Auto merge of #37128 - nrc:depr-attr, r=@nikomatsakis
Deprecate no_debug and custom_derive r? @nikomatsakis
2 parents 7a20864 + 38f993f commit 98cb0c3

File tree

8 files changed

+191
-51
lines changed

8 files changed

+191
-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

+41-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, Stability, with_deprecated_attributes};
4849
use syntax_pos::Span;
4950

5051
use rustc::hir::{self, PatKind};
@@ -741,6 +742,45 @@ 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+
755+
impl LintPass for DeprecatedAttr {
756+
fn get_lints(&self) -> LintArray {
757+
lint_array!(DEPRECATED_ATTR)
758+
}
759+
}
760+
761+
impl EarlyLintPass for DeprecatedAttr {
762+
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
763+
let name = &*attr.name();
764+
with_deprecated_attributes(|depr_attrs| {
765+
for &&(n, _, ref g) in depr_attrs {
766+
if n == name {
767+
if let &AttributeGate::Gated(Stability::Deprecated(link),
768+
ref name,
769+
ref reason,
770+
_) = g {
771+
cx.span_lint(DEPRECATED,
772+
attr.span,
773+
&format!("use of deprecated attribute `{}`: {}. See {}",
774+
name, reason, link));
775+
}
776+
// Returns from the closure, skipping the rest of the loop.
777+
return;
778+
}
779+
}
780+
})
781+
}
782+
}
783+
744784
declare_lint! {
745785
pub UNCONDITIONAL_RECURSION,
746786
Warn,

src/librustc_lint/lib.rs

+2
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;
@@ -103,6 +104,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
103104

104105
add_early_builtin!(sess,
105106
UnusedParens,
107+
DeprecatedAttr,
106108
);
107109

108110
add_builtin!(sess,

src/libsyntax/feature_gate.rs

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

src/libsyntax/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#![cfg_attr(stage0, feature(question_mark))]
3535
#![feature(rustc_diagnostic_macros)]
3636
#![feature(specialization)]
37+
#![feature(dotdot_in_tuple_patterns)]
38+
#![feature(drop_types_in_const)]
3739

3840
extern crate serialize;
3941
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)