]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_lint/src/levels.rs
Rollup merge of #106441 - mllken:abstract-socket-noref, r=joshtriplett
[rust.git] / compiler / rustc_lint / src / levels.rs
index b335f330f5d415511abe8b8e29b3fbe708f90cd8..cca36913dea113650269b7376a8bef5b31da5c31 100644 (file)
@@ -1,10 +1,8 @@
-#![deny(rustc::untranslatable_diagnostic)]
-#![deny(rustc::diagnostic_outside_of_impl)]
 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;
@@ -52,7 +50,7 @@ struct LintStackIndex {
     }
 }
 
-/// Specifications found at this position in the stack.  This map only represents the lints
+/// Specifications found at this position in the stack. This map only represents the lints
 /// found for one set of attributes (like `shallow_lint_levels_on` does).
 ///
 /// We store the level specifications as a linked list.
@@ -165,7 +163,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe
     match attrs.map.range(..) {
         // There is only something to do if there are attributes at all.
         [] => {}
-        // Most of the time, there is only one attribute.  Avoid fetching HIR in that case.
+        // Most of the time, there is only one attribute. Avoid fetching HIR in that case.
         [(local_id, _)] => levels.add_id(HirId { owner, local_id: *local_id }),
         // Otherwise, we need to visit the attributes in source code order, so we fetch HIR and do
         // a standard visit.
@@ -887,10 +885,15 @@ fn add(&mut self, attrs: &[ast::Attribute], is_crate_node: bool, source_hir_id:
                     _ 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 +902,12 @@ fn add(&mut self, attrs: &[ast::Attribute], is_crate_node: bool, source_hir_id:
                         } 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 },
                         );
                     }
                 }