]> git.lizzy.rs Git - rust.git/commitdiff
Make warnings of renamed and removed lints themselves lints
authorBrian Anderson <banderson@mozilla.com>
Sat, 12 Mar 2016 20:46:59 +0000 (20:46 +0000)
committerBrian Anderson <banderson@mozilla.com>
Wed, 23 Mar 2016 23:41:48 +0000 (23:41 +0000)
This adds the `renamed_and_removed_lints` warning, defaulting
to the warning level.

Fixes #31141

src/librustc/lint/builtin.rs
src/librustc/lint/context.rs
src/test/compile-fail/lint-removed-allow.rs [new file with mode: 0644]
src/test/compile-fail/lint-removed.rs
src/test/compile-fail/lint-renamed-allow.rs [new file with mode: 0644]
src/test/run-pass/ifmt.rs

index d99d6afd81285a2aeeec21d7ea33acf1f48435cc..f2371c1819fc429fb7be2f9c50445e1286a45189 100644 (file)
     "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 @@ fn get_lints(&self) -> LintArray {
             CONST_ERR,
             RAW_POINTER_DERIVE,
             TRANSMUTE_FROM_FN_ITEM_TYPES,
-            OVERLAPPING_INHERENT_IMPLS
+            OVERLAPPING_INHERENT_IMPLS,
+            RENAMED_AND_REMOVED_LINTS
         )
     }
 }
index c11e9dc822eb39790cbd5bc2c57698ae372653c3..079a0c94cc5a51567f4fac0c7c9a26fbe19286df 100644 (file)
@@ -1144,13 +1144,13 @@ fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
     }
 }
 
-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)))
         }
diff --git a/src/test/compile-fail/lint-removed-allow.rs b/src/test/compile-fail/lint-removed-allow.rs
new file mode 100644 (file)
index 0000000..159a3d7
--- /dev/null
@@ -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
index e196e128b17128607d6ab5e3c2fed9b8bbd940ac..9069356604131a789305a1a10202d9ce5afdfc24 100644 (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
diff --git a/src/test/compile-fail/lint-renamed-allow.rs b/src/test/compile-fail/lint-renamed-allow.rs
new file mode 100644 (file)
index 0000000..a2426d8
--- /dev/null
@@ -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
index 267b162a1d25c09ab6e55ab1d9c04e224ced3c93..27cafeacc203d73f5911dd7e88c59cc05270e9a0 100644 (file)
@@ -12,7 +12,7 @@
 
 #![deny(warnings)]
 #![allow(unused_must_use)]
-#![allow(unknown_features)]
+#![allow(unused_features)]
 #![feature(box_syntax)]
 #![feature(question_mark)]