mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-16 17:03:35 +00:00
lint: port mutable transmutes diagnostic
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
dbdbdb6874
commit
d071f504f8
@ -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
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user