about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/levels.rs
diff options
context:
space:
mode:
authorRejyr <jerrylwang123@gmail.com>2022-11-10 19:32:30 -0500
committerRejyr <jerrylwang123@gmail.com>2023-01-09 17:07:25 -0500
commit78fce795d8084e288278270438a49df6172dd36c (patch)
tree9907484be2d716443081759c39572c44c1bde096 /compiler/rustc_lint/src/levels.rs
parentca7df9a2a9c4b1f751e91040fe659f682c976919 (diff)
downloadrust-78fce795d8084e288278270438a49df6172dd36c.tar.gz
rust-78fce795d8084e288278270438a49df6172dd36c.zip
refactor: refactor to derive for some lints.
Diffstat (limited to 'compiler/rustc_lint/src/levels.rs')
-rw-r--r--compiler/rustc_lint/src/levels.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs
index b335f330f5d..500b1f36558 100644
--- a/compiler/rustc_lint/src/levels.rs
+++ b/compiler/rustc_lint/src/levels.rs
@@ -4,7 +4,7 @@ use crate::context::{CheckLintNameResult, LintStore};
 use crate::late::unerased_lint_store;
 use crate::lints::{
     DeprecatedLintName, IgnoredUnlessCrateSpecified, OverruledAtributeLint, RenamedOrRemovedLint,
-    UnknownLint,
+    RenamedOrRemovedLintSuggestion, UnknownLint, UnknownLintSuggestion,
 };
 use rustc_ast as ast;
 use rustc_ast_pretty::pprust;
@@ -887,10 +887,15 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
                     _ if !self.warn_about_weird_lints => {}
 
                     CheckLintNameResult::Warning(msg, renamed) => {
+                        let suggestion =
+                            renamed.as_ref().map(|replace| RenamedOrRemovedLintSuggestion {
+                                suggestion: sp,
+                                replace: replace.as_str(),
+                            });
                         self.emit_spanned_lint(
                             RENAMED_AND_REMOVED_LINTS,
                             sp.into(),
-                            RenamedOrRemovedLint { msg, suggestion: sp, renamed },
+                            RenamedOrRemovedLint { msg, suggestion },
                         );
                     }
                     CheckLintNameResult::NoLint(suggestion) => {
@@ -899,10 +904,12 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
                         } else {
                             name.to_string()
                         };
+                        let suggestion = suggestion
+                            .map(|replace| UnknownLintSuggestion { suggestion: sp, replace });
                         self.emit_spanned_lint(
                             UNKNOWN_LINTS,
                             sp.into(),
-                            UnknownLint { name, suggestion: sp, replace: suggestion },
+                            UnknownLint { name, suggestion },
                         );
                     }
                 }