Skip to content

Commit d071f50

Browse files
committed
lint: port mutable transmutes diagnostic
Signed-off-by: David Wood <david.wood@huawei.com>
1 parent dbdbdb6 commit d071f50

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

compiler/rustc_error_messages/locales/en-US/lint.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,6 @@ lint-builtin-no-mangle-generic = functions generic over types or consts must be
349349
350350
lint-builtin-const-no-mangle = const items should never be `#[no_mangle]`
351351
.suggestion = try a static value
352+
353+
lint-builtin-mutable-transmutes =
354+
transmuting &T to &mut T is undefined behavior, even if the reference is unused, consider instead using an UnsafeCell

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,10 +1272,8 @@ impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
12721272
get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (ty1.kind(), ty2.kind()))
12731273
{
12741274
if to_mt == hir::Mutability::Mut && from_mt == hir::Mutability::Not {
1275-
let msg = "transmuting &T to &mut T is undefined behavior, \
1276-
even if the reference is unused, consider instead using an UnsafeCell";
12771275
cx.struct_span_lint(MUTABLE_TRANSMUTES, expr.span, |lint| {
1278-
lint.build(msg).emit();
1276+
lint.build(fluent::lint::builtin_mutable_transmutes).emit();
12791277
});
12801278
}
12811279
}

0 commit comments

Comments
 (0)