about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Wood <david.wood@huawei.com>2022-06-28 10:43:38 +0100
committerDavid Wood <david.wood@huawei.com>2022-06-30 08:59:22 +0100
commit4f7b10f484a42442c3e28bfbb62960460eba85f5 (patch)
tree53f7754fdf2b1c3cfb6a81ba73937ef6f5de3283
parente24833869f17b9032a1fbea69adfdd1e615918b9 (diff)
downloadrust-4f7b10f484a42442c3e28bfbb62960460eba85f5.tar.gz
rust-4f7b10f484a42442c3e28bfbb62960460eba85f5.zip
lint: port unused allocation diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
-rw-r--r--compiler/rustc_error_messages/locales/en-US/lint.ftl3
-rw-r--r--compiler/rustc_lint/src/unused.rs12
2 files changed, 8 insertions, 7 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/lint.ftl b/compiler/rustc_error_messages/locales/en-US/lint.ftl
index 7a2635eae2d..11dfe4fe810 100644
--- a/compiler/rustc_error_messages/locales/en-US/lint.ftl
+++ b/compiler/rustc_error_messages/locales/en-US/lint.ftl
@@ -283,3 +283,6 @@ lint-unused-delim = unnecessary {$delim} around {$item}
     .suggestion = remove these {$delim}
 
 lint-unused-import-braces = braces around {$node} is unnecessary
+
+lint-unused-allocation = unnecessary allocation, use `&` instead
+lint-unused-allocation-mut = unnecessary allocation, use `&mut` instead
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs
index 6fcabde3406..53269d18527 100644
--- a/compiler/rustc_lint/src/unused.rs
+++ b/compiler/rustc_lint/src/unused.rs
@@ -1169,15 +1169,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
         for adj in cx.typeck_results().expr_adjustments(e) {
             if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(_, m)) = adj.kind {
                 cx.struct_span_lint(UNUSED_ALLOCATION, e.span, |lint| {
-                    let msg = match m {
-                        adjustment::AutoBorrowMutability::Not => {
-                            "unnecessary allocation, use `&` instead"
-                        }
+                    lint.build(match m {
+                        adjustment::AutoBorrowMutability::Not => fluent::lint::unused_allocation,
                         adjustment::AutoBorrowMutability::Mut { .. } => {
-                            "unnecessary allocation, use `&mut` instead"
+                            fluent::lint::unused_allocation_mut
                         }
-                    };
-                    lint.build(msg).emit();
+                    })
+                    .emit();
                 });
             }
         }