From 7ea147e4f61ee5defbc9b96620282700eaa8a5f8 Mon Sep 17 00:00:00 2001 From: Ramnivas Laddad Date: Thu, 17 Mar 2022 13:43:23 -0700 Subject: [PATCH] Add an explanation shared to exclusive transmute (#344) --- src/transmutes.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/transmutes.md b/src/transmutes.md index 1b2d699..2109848 100644 --- a/src/transmutes.md +++ b/src/transmutes.md @@ -19,7 +19,10 @@ boggling. * Transmute has an overloaded return type. If you do not specify the return type it may produce a surprising type to satisfy inference. -* Transmuting an `&` to `&mut` is UB. +* Transmuting an `&` to `&mut` is UB. While certain usages may *appear* safe, + note that the Rust optimizer is free to assume that a shared reference won't + change through its lifetime and thus such transmutation will run afoul of those + assumptions. So: * Transmuting an `&` to `&mut` is *always* UB. * No you can't do it. * No you're not special.