about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src/check_unused.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_hir_analysis/src/check_unused.rs')
-rw-r--r--compiler/rustc_hir_analysis/src/check_unused.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/compiler/rustc_hir_analysis/src/check_unused.rs b/compiler/rustc_hir_analysis/src/check_unused.rs
index aa5db4f6aa7..ed23dc2a827 100644
--- a/compiler/rustc_hir_analysis/src/check_unused.rs
+++ b/compiler/rustc_hir_analysis/src/check_unused.rs
@@ -35,11 +35,12 @@ fn check_unused_traits(tcx: TyCtxt<'_>, (): ()) {
             continue;
         }
         let (path, _) = item.expect_use();
-        let msg = if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(path.span) {
-            format!("unused import: `{snippet}`")
-        } else {
-            "unused import".to_owned()
-        };
-        tcx.node_span_lint(lint::builtin::UNUSED_IMPORTS, item.hir_id(), path.span, msg, |_| {});
+        tcx.node_span_lint(lint::builtin::UNUSED_IMPORTS, item.hir_id(), path.span, |lint| {
+            if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(path.span) {
+                lint.primary_message(format!("unused import: `{snippet}`"));
+            } else {
+                lint.primary_message("unused import");
+            }
+        });
     }
 }