提交 addde1fd 编写于 作者: B Brian Anderson

Make warnings of renamed and removed lints themselves lints

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

Fixes #31141
上级 98f0a912
...@@ -160,6 +160,12 @@ ...@@ -160,6 +160,12 @@
"two overlapping inherent impls define an item with the same name were erroneously allowed" "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 /// Does nothing as a lint pass, but registers some `Lint`s
/// which are used by other parts of the compiler. /// which are used by other parts of the compiler.
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
...@@ -191,7 +197,8 @@ fn get_lints(&self) -> LintArray { ...@@ -191,7 +197,8 @@ fn get_lints(&self) -> LintArray {
CONST_ERR, CONST_ERR,
RAW_POINTER_DERIVE, RAW_POINTER_DERIVE,
TRANSMUTE_FROM_FN_ITEM_TYPES, TRANSMUTE_FROM_FN_ITEM_TYPES,
OVERLAPPING_INHERENT_IMPLS OVERLAPPING_INHERENT_IMPLS,
RENAMED_AND_REMOVED_LINTS
) )
} }
} }
......
...@@ -1144,13 +1144,13 @@ fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { ...@@ -1144,13 +1144,13 @@ fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
} }
} }
enum CheckLintNameResult<'a> { enum CheckLintNameResult {
Ok, Ok,
// Lint doesn't exist // Lint doesn't exist
NoLint, NoLint,
// The lint is either renamed or removed and a warning was // The lint is either renamed or removed. This is the warning
// generated in the DiagnosticBuilder // message.
Mentioned(DiagnosticBuilder<'a>) Warning(String)
} }
/// Checks the name of a lint for its existence, and whether it was /// Checks the name of a lint for its existence, and whether it was
...@@ -1160,27 +1160,18 @@ enum CheckLintNameResult<'a> { ...@@ -1160,27 +1160,18 @@ enum CheckLintNameResult<'a> {
/// it emits non-fatal warnings and there are *two* lint passes that /// it emits non-fatal warnings and there are *two* lint passes that
/// inspect attributes, this is only run from the late pass to avoid /// inspect attributes, this is only run from the late pass to avoid
/// printing duplicate warnings. /// printing duplicate warnings.
fn check_lint_name<'a>(sess: &'a Session, fn check_lint_name(lint_cx: &LintStore,
lint_cx: &LintStore, lint_name: &str) -> CheckLintNameResult {
lint_name: &str,
span: Option<Span>) -> CheckLintNameResult<'a> {
match lint_cx.by_name.get(lint_name) { match lint_cx.by_name.get(lint_name) {
Some(&Renamed(ref new_name, _)) => { Some(&Renamed(ref new_name, _)) => {
let warning = format!("lint {} has been renamed to {}", CheckLintNameResult::Warning(
lint_name, new_name); 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)
}, },
Some(&Removed(ref reason)) => { Some(&Removed(ref reason)) => {
let warning = format!("lint {} has been removed: {}", lint_name, reason); CheckLintNameResult::Warning(
let db = match span { format!("lint {} has been removed: {}", lint_name, reason)
Some(span) => sess.struct_span_warn(span, &warning[..]), )
None => sess.struct_warn(&warning[..])
};
CheckLintNameResult::Mentioned(db)
}, },
None => { None => {
match lint_cx.lint_groups.get(lint_name) { match lint_cx.lint_groups.get(lint_name) {
...@@ -1209,10 +1200,12 @@ fn check_lint_name_attribute(cx: &LateContext, attr: &ast::Attribute) { ...@@ -1209,10 +1200,12 @@ fn check_lint_name_attribute(cx: &LateContext, attr: &ast::Attribute) {
continue; continue;
} }
Ok((lint_name, _, span)) => { 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::Ok => (),
CheckLintNameResult::Mentioned(mut db) => { CheckLintNameResult::Warning(ref msg) => {
db.emit(); cx.span_lint(builtin::RENAMED_AND_REMOVED_LINTS,
span, msg);
} }
CheckLintNameResult::NoLint => { CheckLintNameResult::NoLint => {
cx.span_lint(builtin::UNKNOWN_LINTS, span, cx.span_lint(builtin::UNKNOWN_LINTS, span,
...@@ -1228,9 +1221,11 @@ fn check_lint_name_attribute(cx: &LateContext, attr: &ast::Attribute) { ...@@ -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 // Checks the validity of lint names derived from the command line
fn check_lint_name_cmdline(sess: &Session, lint_cx: &LintStore, fn check_lint_name_cmdline(sess: &Session, lint_cx: &LintStore,
lint_name: &str, level: Level) { 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::Ok => None,
CheckLintNameResult::Mentioned(db) => Some(db), CheckLintNameResult::Warning(ref msg) => {
Some(sess.struct_warn(msg))
},
CheckLintNameResult::NoLint => { CheckLintNameResult::NoLint => {
Some(sess.struct_err(&format!("unknown lint: `{}`", lint_name))) Some(sess.struct_err(&format!("unknown lint: `{}`", lint_name)))
} }
......
// 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
...@@ -8,9 +8,11 @@ ...@@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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 // cc #30346
#[deny(raw_pointer_derive)] //~ WARN raw_pointer_derive has been removed #[deny(raw_pointer_derive)] //~ WARN raw_pointer_derive has been removed
#[deny(warnings)] #[deny(unused_variables)]
fn main() { let unused = (); } //~ ERR unused fn main() { let unused = (); } //~ ERR unused
// 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
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#![deny(warnings)] #![deny(warnings)]
#![allow(unused_must_use)] #![allow(unused_must_use)]
#![allow(unknown_features)] #![allow(unused_features)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(question_mark)] #![feature(question_mark)]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册