Skip to content

Commit 36a1141

Browse files
committed
Make message for &T -> &mut T transmute more accurate
1 parent 092e1c9 commit 36a1141

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

compiler/rustc_lint/src/builtin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ declare_lint! {
12481248
/// [`UnsafeCell`]: https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html
12491249
MUTABLE_TRANSMUTES,
12501250
Deny,
1251-
"mutating transmuted &mut T from &T may cause undefined behavior"
1251+
"transmuting &T to &mut T is undefined behavior, even if the reference is unused"
12521252
}
12531253

12541254
declare_lint_pass!(MutableTransmutes => [MUTABLE_TRANSMUTES]);
@@ -1260,8 +1260,8 @@ impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
12601260
get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (ty1.kind(), ty2.kind()))
12611261
{
12621262
if to_mt == hir::Mutability::Mut && from_mt == hir::Mutability::Not {
1263-
let msg = "mutating transmuted &mut T from &T may cause undefined behavior, \
1264-
consider instead using an UnsafeCell";
1263+
let msg = "transmuting &T to &mut T is undefined behavior, \
1264+
even if the reference is unused, consider instead using an UnsafeCell";
12651265
cx.struct_span_lint(MUTABLE_TRANSMUTES, expr.span, |lint| lint.build(msg).emit());
12661266
}
12671267
}

src/test/ui/transmute/transmute-imut-to-mut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ use std::mem::transmute;
44

55
fn main() {
66
let _a: &mut u8 = unsafe { transmute(&1u8) };
7-
//~^ ERROR mutating transmuted &mut T from &T may cause undefined behavior
7+
//~^ ERROR transmuting &T to &mut T is undefined behavior, even if the reference is unused, consider instead using an UnsafeCell
88
}

src/test/ui/transmute/transmute-imut-to-mut.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: mutating transmuted &mut T from &T may cause undefined behavior, consider instead using an UnsafeCell
1+
error: transmuting &T to &mut T is undefined behavior, even if the reference is unused, consider instead using an UnsafeCell
22
--> $DIR/transmute-imut-to-mut.rs:6:32
33
|
44
LL | let _a: &mut u8 = unsafe { transmute(&1u8) };

0 commit comments

Comments
 (0)