diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-05-11 13:16:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-11 13:16:41 +0200 |
| commit | 8eac6d2333a11bc84f04d0a7ada0efc08f763cfe (patch) | |
| tree | 0a9479750225e8c710c1104087cf45841d54bae6 /compiler | |
| parent | 7d7a182c291d086249365e3690554a0c1a403ac5 (diff) | |
| parent | 2bb25d3f4ac8796a50f45409f3ef461ce83295f3 (diff) | |
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.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_lint/src/reference_casting.rs | 6 |
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; } |
