1
Fork 0

Auto merge of #105274 - saethlin:instcombine-mut-ref, r=cjgillot

Enable instcombine for mutable reborrows

`instcombine` used to contain this comment, which is no longer accurate because there it is fine to copy `&mut _` in MIR:
```rust
// The dereferenced place must have type `&_`, so that we don't copy `&mut _`.
```
So let's try replacing that check with something much more permissive...
This commit is contained in:
bors 2023-02-17 20:50:11 +00:00
commit 231bcd131d
4 changed files with 9 additions and 31 deletions

View file

@ -110,11 +110,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
fn combine_ref_deref(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
if let Rvalue::Ref(_, _, place) = rvalue {
if let Some((base, ProjectionElem::Deref)) = place.as_ref().last_projection() {
if let ty::Ref(_, _, Mutability::Not) =
base.ty(self.local_decls, self.tcx).ty.kind()
{
// The dereferenced place must have type `&_`, so that we don't copy `&mut _`.
} else {
if rvalue.ty(self.local_decls, self.tcx) != base.ty(self.local_decls, self.tcx).ty {
return;
}