Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate no_debug and custom_derive #37128

Merged
merged 5 commits into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,4 @@ pub enum LintSource {
pub type LevelSource = (Level, LintSource);

pub mod builtin;

mod context;
51 changes: 50 additions & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ use rustc::traits::{self, Reveal};
use rustc::hir::map as hir_map;
use util::nodemap::NodeSet;
use lint::{Level, LateContext, LintContext, LintArray, Lint};
use lint::{LintPass, LateLintPass};
use lint::{LintPass, LateLintPass, EarlyLintPass, EarlyContext};

use std::collections::HashSet;

use syntax::ast;
use syntax::attr;
use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_attributes};
use syntax_pos::Span;

use rustc::hir::{self, PatKind};
Expand Down Expand Up @@ -741,6 +742,54 @@ impl LateLintPass for Deprecated {
}
}

declare_lint! {
DEPRECATED_ATTR,
Warn,
"detects use of deprecated attributes"
}

/// Checks for use of attributes which have been deprecated.
#[derive(Clone)]
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 {
fn get_lints(&self) -> LintArray {
lint_array!(DEPRECATED_ATTR)
}
}

impl EarlyLintPass for DeprecatedAttr {
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
let name = &*attr.name();
for &&(n, _, ref g) in &self.depr_attrs {
if n == name {
if let &AttributeGate::Gated(Stability::Deprecated(link),
ref name,
ref reason,
_) = g {
cx.span_lint(DEPRECATED,
attr.span,
&format!("use of deprecated attribute `{}`: {}. See {}",
name, reason, link));
}
return;
}
}
}
}

declare_lint! {
pub UNCONDITIONAL_RECURSION,
Warn,
Expand Down
13 changes: 13 additions & 0 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#![feature(rustc_private)]
#![feature(slice_patterns)]
#![feature(staged_api)]
#![feature(dotdot_in_tuple_patterns)]

#[macro_use]
extern crate syntax;
Expand Down Expand Up @@ -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 {
($sess:ident, $name:expr, $($lint:ident),*) => (
store.register_group($sess, false, $name, vec![$(LintId::of($lint)),*]);
Expand All @@ -105,6 +114,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
UnusedParens,
);

add_early_builtin_with_new!(sess,
DeprecatedAttr,
);

add_builtin!(sess,
HardwiredLints,
WhileTrue,
Expand Down
164 changes: 116 additions & 48 deletions src/libsyntax/feature_gate.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/libsyntax/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#![cfg_attr(stage0, feature(question_mark))]
#![feature(rustc_diagnostic_macros)]
#![feature(specialization)]
#![feature(dotdot_in_tuple_patterns)]

extern crate serialize;
extern crate term;
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax_ext/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_CUSTOM_DERIVE);
} else {
cx.span_warn(titem.span, feature_gate::EXPLAIN_DEPR_CUSTOM_DERIVE);
let name = intern_and_get_ident(&format!("derive_{}", tname));
let mitem = cx.meta_word(titem.span, name);
new_attributes.push(cx.attribute(mitem.span, mitem));
Expand Down
4 changes: 3 additions & 1 deletion src/test/compile-fail/deriving-meta-unknown-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-tidy-linelength

#[derive(Eqr)]
//~^ ERROR `#[derive]` for custom traits is not stable enough for use and is subject to change
//~^ ERROR `#[derive]` for custom traits is not stable enough for use. It is deprecated and will be removed in v1.15 (see issue #29644)
struct Foo;

pub fn main() {}
15 changes: 15 additions & 0 deletions src/test/compile-fail/feature-gate-no-debug-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![deny(deprecated)]
#![feature(no_debug)]

#[no_debug] //~ ERROR use of deprecated attribute `no_debug`
fn main() {}