about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Wood <david.wood@huawei.com>2022-06-28 13:45:49 +0100
committerDavid Wood <david.wood@huawei.com>2022-06-30 08:59:22 +0100
commitd071f504f80767b1686b176b72fdcf87a35f8dca (patch)
tree94ad62983f07a631a99b8162abb14e2e86b3f187
parentdbdbdb68740dd3be9cea059dd5cb6067c45f38d7 (diff)
downloadrust-d071f504f80767b1686b176b72fdcf87a35f8dca.tar.gz
rust-d071f504f80767b1686b176b72fdcf87a35f8dca.zip
lint: port mutable transmutes diagnostic
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/builtin.rs4
2 files changed, 4 insertions, 3 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/lint.ftl b/compiler/rustc_error_messages/locales/en-US/lint.ftl
index cbe7e15a723..de2d21ff355 100644
--- a/compiler/rustc_error_messages/locales/en-US/lint.ftl
+++ b/compiler/rustc_error_messages/locales/en-US/lint.ftl
@@ -349,3 +349,6 @@ lint-builtin-no-mangle-generic = functions generic over types or consts must be
 
 lint-builtin-const-no-mangle = const items should never be `#[no_mangle]`
     .suggestion = try a static value
+
+lint-builtin-mutable-transmutes =
+    transmuting &T to &mut T is undefined behavior, even if the reference is unused, consider instead using an UnsafeCell
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs
index 6dfcc0eec49..c2729b543c4 100644
--- a/compiler/rustc_lint/src/builtin.rs
+++ b/compiler/rustc_lint/src/builtin.rs
@@ -1272,10 +1272,8 @@ impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
             get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (ty1.kind(), ty2.kind()))
         {
             if to_mt == hir::Mutability::Mut && from_mt == hir::Mutability::Not {
-                let msg = "transmuting &T to &mut T is undefined behavior, \
-                    even if the reference is unused, consider instead using an UnsafeCell";
                 cx.struct_span_lint(MUTABLE_TRANSMUTES, expr.span, |lint| {
-                    lint.build(msg).emit();
+                    lint.build(fluent::lint::builtin_mutable_transmutes).emit();
                 });
             }
         }