about summary refs log tree commit diff
diff options
context:
space:
mode:
author5225225 <5225225@mailbox.org>2022-01-09 22:15:23 +0000
committer5225225 <5225225@mailbox.org>2022-01-09 23:31:57 +0000
commit36a11417fafcbfae0500884df2d4b6dd2c5e5a0f (patch)
treecc5028df556c92a96758b13b593adac75cc86f34
parent092e1c9d23158d81be27bb6f71bdd0c6282478fb (diff)
downloadrust-36a11417fafcbfae0500884df2d4b6dd2c5e5a0f.tar.gz
rust-36a11417fafcbfae0500884df2d4b6dd2c5e5a0f.zip
Make message for &T -> &mut T transmute more accurate
-rw-r--r--compiler/rustc_lint/src/builtin.rs6
-rw-r--r--src/test/ui/transmute/transmute-imut-to-mut.rs2
-rw-r--r--src/test/ui/transmute/transmute-imut-to-mut.stderr2
3 files changed, 5 insertions, 5 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs
index c0384875a47..2b373a53b63 100644
--- a/compiler/rustc_lint/src/builtin.rs
+++ b/compiler/rustc_lint/src/builtin.rs
@@ -1248,7 +1248,7 @@ declare_lint! {
     /// [`UnsafeCell`]: https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html
     MUTABLE_TRANSMUTES,
     Deny,
-    "mutating transmuted &mut T from &T may cause undefined behavior"
+    "transmuting &T to &mut T is undefined behavior, even if the reference is unused"
 }
 
 declare_lint_pass!(MutableTransmutes => [MUTABLE_TRANSMUTES]);
@@ -1260,8 +1260,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 = "mutating transmuted &mut T from &T may cause undefined behavior, \
-                               consider instead using an UnsafeCell";
+                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());
             }
         }
diff --git a/src/test/ui/transmute/transmute-imut-to-mut.rs b/src/test/ui/transmute/transmute-imut-to-mut.rs
index 8e34e0ae8c7..9f3f76c1ef3 100644
--- a/src/test/ui/transmute/transmute-imut-to-mut.rs
+++ b/src/test/ui/transmute/transmute-imut-to-mut.rs
@@ -4,5 +4,5 @@ use std::mem::transmute;
 
 fn main() {
     let _a: &mut u8 = unsafe { transmute(&1u8) };
-    //~^ ERROR mutating transmuted &mut T from &T may cause undefined behavior
+    //~^ ERROR transmuting &T to &mut T is undefined behavior, even if the reference is unused, consider instead using an UnsafeCell
 }
diff --git a/src/test/ui/transmute/transmute-imut-to-mut.stderr b/src/test/ui/transmute/transmute-imut-to-mut.stderr
index d323c1a73b7..1e9dff3ce89 100644
--- a/src/test/ui/transmute/transmute-imut-to-mut.stderr
+++ b/src/test/ui/transmute/transmute-imut-to-mut.stderr
@@ -1,4 +1,4 @@
-error: mutating transmuted &mut T from &T may cause undefined behavior, consider instead using an UnsafeCell
+error: transmuting &T to &mut T is undefined behavior, even if the reference is unused, consider instead using an UnsafeCell
   --> $DIR/transmute-imut-to-mut.rs:6:32
    |
 LL |     let _a: &mut u8 = unsafe { transmute(&1u8) };