Remove duplicate remove_outer_derefs and refactor mod deref#573
Remove duplicate remove_outer_derefs and refactor mod deref#573kkysen wants to merge 5 commits intotests.refs.fieldsfrom
remove_outer_derefs and refactor mod deref#573Conversation
…in terms of `try_remove_outer_deref_as_ref` so we know they're in sync.
…and this lets us eliminate duplicate calls.
remove_outer_derefs and refactor mod deref
…ng `try_remove_outer_deref`.
It encouraged an anti-pattern anyways, using `has_outer_deref` and then `remove_outer_deref` instead of `try_remove_outer_deref`.
| Rvalue::AddressOf(_, p) => { | ||
| // Instrument which local's address is taken | ||
| self.loc(location.successor_within_block(), addr_local_fn) | ||
| let source = try_remove_outer_deref(*p, self.tcx()) |
There was a problem hiding this comment.
i don't want to combine these, there are more complicated cases incoming and it'll be much clearer if they're separate
| // this is a reborrow or field reference, i.e. _2 = &(*_1) | ||
| let source = remove_outer_deref(*p, self.tcx()); | ||
| if let BorrowKind::Mut { .. } = bkind { | ||
| let source = try_remove_outer_deref(*p, self.tcx()); |
There was a problem hiding this comment.
i don't want to combine these, there are more complicated cases incoming and it'll be much clearer if they're separate
My original idea uses |
|
|
|
I understand there might be more complex logic coming, so I shouldn't combine the logic in the way I did, but I don't think combining |
This refactors
mod deref, implementing most of the functions there in terms of onetry_remove_outer_deref_as_refso that we know they're all in sync. Also,try_remove_outer_derefis added so that you don't have to do separatehas_outer_derefandremove_outer_derefcalls.Then I used this to de-duplicate the 1
has_outer_refand 2remove_outer_derefcalls in theRValue::{AddressOf,Ref}matcharms by combining the arms and usingtry_remove_outer_deref.Then I used
applyto simplify the conditional builder logic. It's quite a small but useful dependency for functional, chaining code.The remaining code is still quite similar between the
RValue::AddressOfandRvalue::Refmatcharms, so maybe we can refactor that into common code as well.