about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/reference_casting.rs
diff options
context:
space:
mode:
authorBen Kimock <kimockb@gmail.com>2024-05-10 12:27:49 -0400
committerBen Kimock <kimockb@gmail.com>2024-05-10 12:33:07 -0400
commit2bb25d3f4ac8796a50f45409f3ef461ce83295f3 (patch)
treebcaf1c55718cab13aad6d83eddb1b0bfc8d2fd5d /compiler/rustc_lint/src/reference_casting.rs
parent8f9080db423ca0fb6bef0686ce9a93940cdf1f13 (diff)
downloadrust-2bb25d3f4ac8796a50f45409f3ef461ce83295f3.tar.gz
rust-2bb25d3f4ac8796a50f45409f3ef461ce83295f3.zip
Handle Deref expressions in invalid_reference_casting
Diffstat (limited to 'compiler/rustc_lint/src/reference_casting.rs')
-rw-r--r--compiler/rustc_lint/src/reference_casting.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/compiler/rustc_lint/src/reference_casting.rs b/compiler/rustc_lint/src/reference_casting.rs
index b80e90c25a3..34153e3a220 100644
--- a/compiler/rustc_lint/src/reference_casting.rs
+++ b/compiler/rustc_lint/src/reference_casting.rs
@@ -202,8 +202,10 @@ fn is_cast_to_bigger_memory_layout<'tcx>(
 
     // if the current expr looks like this `&mut expr[index]` then just looking
     // at `expr[index]` won't give us the underlying allocation, so we just skip it
-    // the same logic applies field access like `&mut expr.field`
-    if let ExprKind::Index(..) | ExprKind::Field(..) = e_alloc.kind {
+    // the same logic applies field access `&mut expr.field` and reborrows `&mut *expr`.
+    if let ExprKind::Index(..) | ExprKind::Field(..) | ExprKind::Unary(UnOp::Deref, ..) =
+        e_alloc.kind
+    {
         return None;
     }