diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index d99d6afd812..f2371c1819f 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -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 ) } } diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index c11e9dc822e..079a0c94cc5 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -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) -> 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))) } diff --git a/src/test/compile-fail/lint-removed-allow.rs b/src/test/compile-fail/lint-removed-allow.rs new file mode 100644 index 00000000000..159a3d74603 --- /dev/null +++ b/src/test/compile-fail/lint-removed-allow.rs @@ -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 or the MIT license +// , 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 diff --git a/src/test/compile-fail/lint-removed.rs b/src/test/compile-fail/lint-removed.rs index e196e128b17..90693566041 100644 --- a/src/test/compile-fail/lint-removed.rs +++ b/src/test/compile-fail/lint-removed.rs @@ -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 diff --git a/src/test/compile-fail/lint-renamed-allow.rs b/src/test/compile-fail/lint-renamed-allow.rs new file mode 100644 index 00000000000..a2426d80f71 --- /dev/null +++ b/src/test/compile-fail/lint-renamed-allow.rs @@ -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 or the MIT license +// , 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 diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 267b162a1d2..27cafeacc20 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -12,7 +12,7 @@ #![deny(warnings)] #![allow(unused_must_use)] -#![allow(unknown_features)] +#![allow(unused_features)] #![feature(box_syntax)] #![feature(question_mark)]