1
Fork 0

Rollup merge of #124978 - saethlin:ref-casting_derefs, r=Urgau,Nilstrieb

Handle Deref expressions in invalid_reference_casting

Similar to https://github.com/rust-lang/rust/pull/124908

See https://github.com/rust-lang/rust/issues/124951 for context; this PR fixes the last of the known false postiive cases with this lint that we encounter in Crater.
This commit is contained in:
Matthias Krüger 2024-05-11 13:16:41 +02:00 committed by GitHub
commit 8eac6d2333
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View file

@ -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;
}