Auto merge of #32219 - brson:lints, r=alexcrichton

Make warnings of renamed and removed lints themselves lints

This adds the `renamed_and_removed_lints` warning, defaulting
to the warning level.

Fixes #31141
This commit is contained in:
bors 2016-03-23 23:09:47 -07:00
commit dc1f6831eb
6 changed files with 68 additions and 30 deletions

View File

@ -160,6 +160,12 @@ declare_lint! {
"two overlapping inherent impls define an item with the same name were erroneously allowed"
}
declare_lint! {
pub RENAMED_AND_REMOVED_LINTS,
Warn,
"lints that have been renamed or removed"
}
/// Does nothing as a lint pass, but registers some `Lint`s
/// which are used by other parts of the compiler.
#[derive(Copy, Clone)]
@ -191,7 +197,8 @@ impl LintPass for HardwiredLints {
CONST_ERR,
RAW_POINTER_DERIVE,
TRANSMUTE_FROM_FN_ITEM_TYPES,
OVERLAPPING_INHERENT_IMPLS
OVERLAPPING_INHERENT_IMPLS,
RENAMED_AND_REMOVED_LINTS
)
}
}

View File

@ -1144,13 +1144,13 @@ impl LateLintPass for GatherNodeLevels {
}
}
enum CheckLintNameResult<'a> {
enum CheckLintNameResult {
Ok,
// Lint doesn't exist
NoLint,
// The lint is either renamed or removed and a warning was
// generated in the DiagnosticBuilder
Mentioned(DiagnosticBuilder<'a>)
// The lint is either renamed or removed. This is the warning
// message.
Warning(String)
}
/// Checks the name of a lint for its existence, and whether it was
@ -1160,27 +1160,18 @@ enum CheckLintNameResult<'a> {
/// it emits non-fatal warnings and there are *two* lint passes that
/// inspect attributes, this is only run from the late pass to avoid
/// printing duplicate warnings.
fn check_lint_name<'a>(sess: &'a Session,
lint_cx: &LintStore,
lint_name: &str,
span: Option<Span>) -> CheckLintNameResult<'a> {
fn check_lint_name(lint_cx: &LintStore,
lint_name: &str) -> CheckLintNameResult {
match lint_cx.by_name.get(lint_name) {
Some(&Renamed(ref new_name, _)) => {
let warning = format!("lint {} has been renamed to {}",
lint_name, new_name);
let db = match span {
Some(span) => sess.struct_span_warn(span, &warning[..]),
None => sess.struct_warn(&warning[..]),
};
CheckLintNameResult::Mentioned(db)
CheckLintNameResult::Warning(
format!("lint {} has been renamed to {}", lint_name, new_name)
)
},
Some(&Removed(ref reason)) => {
let warning = format!("lint {} has been removed: {}", lint_name, reason);
let db = match span {
Some(span) => sess.struct_span_warn(span, &warning[..]),
None => sess.struct_warn(&warning[..])
};
CheckLintNameResult::Mentioned(db)
CheckLintNameResult::Warning(
format!("lint {} has been removed: {}", lint_name, reason)
)
},
None => {
match lint_cx.lint_groups.get(lint_name) {
@ -1209,10 +1200,12 @@ fn check_lint_name_attribute(cx: &LateContext, attr: &ast::Attribute) {
continue;
}
Ok((lint_name, _, span)) => {
match check_lint_name(&cx.tcx.sess, &cx.lints, &lint_name[..], Some(span)) {
match check_lint_name(&cx.lints,
&lint_name[..]) {
CheckLintNameResult::Ok => (),
CheckLintNameResult::Mentioned(mut db) => {
db.emit();
CheckLintNameResult::Warning(ref msg) => {
cx.span_lint(builtin::RENAMED_AND_REMOVED_LINTS,
span, msg);
}
CheckLintNameResult::NoLint => {
cx.span_lint(builtin::UNKNOWN_LINTS, span,
@ -1228,9 +1221,11 @@ fn check_lint_name_attribute(cx: &LateContext, attr: &ast::Attribute) {
// Checks the validity of lint names derived from the command line
fn check_lint_name_cmdline(sess: &Session, lint_cx: &LintStore,
lint_name: &str, level: Level) {
let db = match check_lint_name(sess, lint_cx, lint_name, None) {
let db = match check_lint_name(lint_cx, lint_name) {
CheckLintNameResult::Ok => None,
CheckLintNameResult::Mentioned(db) => Some(db),
CheckLintNameResult::Warning(ref msg) => {
Some(sess.struct_warn(msg))
},
CheckLintNameResult::NoLint => {
Some(sess.struct_err(&format!("unknown lint: `{}`", lint_name)))
}

View File

@ -0,0 +1,17 @@
// 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.
// No warnings about removed lint when
// allow(renamed_and_removed_lints)
#[deny(raw_pointer_derive)]
#[allow(renamed_and_removed_lints)]
#[deny(unused_variables)]
fn main() { let unused = (); } //~ ERR unused

View File

@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// The raw_pointer_derived lint only warns about its own removal
// The raw_pointer_derived lint was removed, but is now reported by
// the renamed_and_removed_lints lint, which means it's a warning by
// default, and allowed in cargo dependency builds.
// cc #30346
#[deny(raw_pointer_derive)] //~ WARN raw_pointer_derive has been removed
#[deny(warnings)]
#[deny(unused_variables)]
fn main() { let unused = (); } //~ ERR unused

View File

@ -0,0 +1,17 @@
// 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.
// No warnings about renamed lint when
// allow(renamed_and_removed_lints)
#[deny(unknown_features)]
#[allow(renamed_and_removed_lints)]
#[deny(unused)]
fn main() { let unused = (); } //~ ERR unused

View File

@ -12,7 +12,7 @@
#![deny(warnings)]
#![allow(unused_must_use)]
#![allow(unknown_features)]
#![allow(unused_features)]
#![feature(box_syntax)]
#![feature(question_mark)]