]> git.lizzy.rs Git - rust.git/commitdiff
structured suggestion for renamed-and-removed-lints
authorZack M. Davis <code@zackmdavis.net>
Sun, 15 Jul 2018 03:52:40 +0000 (20:52 -0700)
committerZack M. Davis <code@zackmdavis.net>
Sun, 15 Jul 2018 05:09:27 +0000 (22:09 -0700)
src/librustc/lint/context.rs
src/librustc/lint/levels.rs
src/test/compile-fail/lint-removed-cmdline.rs
src/test/compile-fail/lint-removed.rs
src/test/compile-fail/lint-renamed-cmdline.rs
src/test/compile-fail/lint-renamed.rs

index c9874f510f7314653e795c09d2e8e88ec88fa912..2a44845b980dba83a0d3e511b4cc86869cf67c8f 100644 (file)
@@ -131,8 +131,8 @@ pub enum CheckLintNameResult<'a> {
     /// Lint doesn't exist
     NoLint,
     /// The lint is either renamed or removed. This is the warning
-    /// message.
-    Warning(String),
+    /// message, and an optional new name (`None` if removed).
+    Warning(String, Option<String>),
 }
 
 impl LintStore {
@@ -280,7 +280,7 @@ pub fn check_lint_name_cmdline(&self,
                                    level: Level) {
         let db = match self.check_lint_name(lint_name) {
             CheckLintNameResult::Ok(_) => None,
-            CheckLintNameResult::Warning(ref msg) => {
+            CheckLintNameResult::Warning(ref msg, _) => {
                 Some(sess.struct_warn(msg))
             },
             CheckLintNameResult::NoLint => {
@@ -313,12 +313,14 @@ pub fn check_lint_name(&self, lint_name: &str) -> CheckLintNameResult {
         match self.by_name.get(lint_name) {
             Some(&Renamed(ref new_name, _)) => {
                 CheckLintNameResult::Warning(
-                    format!("lint {} has been renamed to {}", lint_name, new_name)
+                    format!("lint `{}` has been renamed to `{}`", lint_name, new_name),
+                    Some(new_name.to_owned())
                 )
             },
             Some(&Removed(ref reason)) => {
                 CheckLintNameResult::Warning(
-                    format!("lint {} has been removed: {}", lint_name, reason)
+                    format!("lint `{}` has been removed: `{}`", lint_name, reason),
+                    None
                 )
             },
             None => {
index a1b84a7b716efdf4d4c9ea750bb34da9db858911..b7b6aba970bff21c76a07c1e3f7a65913a7fec5e 100644 (file)
@@ -260,19 +260,27 @@ pub fn push(&mut self, attrs: &[ast::Attribute]) -> BuilderPush {
 
                     _ if !self.warn_about_weird_lints => {}
 
-                    CheckLintNameResult::Warning(ref msg) => {
+                    CheckLintNameResult::Warning(msg, renamed) => {
                         let lint = builtin::RENAMED_AND_REMOVED_LINTS;
                         let (level, src) = self.sets.get_lint_level(lint,
                                                                     self.cur,
                                                                     Some(&specs),
                                                                     &sess);
-                        lint::struct_lint_level(self.sess,
-                                                lint,
-                                                level,
-                                                src,
-                                                Some(li.span.into()),
-                                                msg)
-                            .emit();
+                        let mut err = lint::struct_lint_level(self.sess,
+                                                              lint,
+                                                              level,
+                                                              src,
+                                                              Some(li.span.into()),
+                                                              &msg);
+                        if let Some(new_name) = renamed {
+                            err.span_suggestion_with_applicability(
+                                li.span,
+                                "use the new name",
+                                new_name,
+                                Applicability::MachineApplicable
+                            );
+                        }
+                        err.emit();
                     }
                     CheckLintNameResult::NoLint => {
                         let lint = builtin::UNKNOWN_LINTS;
index e1da5086612fd7d5eacb4bd77bce414550ada9e6..09725b201466a969a7c5a055c7576e135e69d308 100644 (file)
@@ -13,7 +13,7 @@
 
 // compile-flags:-D raw_pointer_derive
 
-// error-pattern:lint raw_pointer_derive has been removed
+// error-pattern:lint `raw_pointer_derive` has been removed
 // error-pattern:requested on the command line with `-D raw_pointer_derive`
 
 #![warn(unused)]
index aa7f535aa64b733849a6aba2e92a1ab6a8be815d..4e53852008f13dcb880b5fd1c55d9ab6f642c3b4 100644 (file)
@@ -13,6 +13,6 @@
 // default, and allowed in cargo dependency builds.
 // 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(unused_variables)]
 fn main() { let unused = (); } //~ ERROR unused
index 3b352b384ff99609e55386d3ac3015e2e7e16d98..a5246206d9504726872fd4e565c5cf536eb6010d 100644 (file)
@@ -10,7 +10,7 @@
 
 // compile-flags:-D unknown_features
 
-// error-pattern:lint unknown_features has been renamed to unused_features
+// error-pattern:lint `unknown_features` has been renamed to `unused_features`
 // error-pattern:requested on the command line with `-D unknown_features`
 // error-pattern:unused
 
index 9e10ddf89ac33143887eaee31d55eec38c15a271..afe4aee7a1d947ef43394060654f99090464cf41 100644 (file)
@@ -8,6 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#[deny(unknown_features)] //~ WARN lint unknown_features has been renamed to unused_features
+#[deny(unknown_features)] //~ WARN lint `unknown_features` has been renamed to `unused_features`
 #[deny(unused)]
 fn main() { let unused = (); } //~ ERROR unused