Use PlaceRef more consistently in rustc_mir

This commit is contained in:
Olivia Crain
2021-01-09 23:33:38 -06:00
parent 410a546fc5
commit 65b5e4386b
10 changed files with 103 additions and 124 deletions

View File

@@ -277,11 +277,9 @@ impl OptimizationFinder<'b, 'tcx> {
impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> {
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
if let Rvalue::Ref(_, _, place) = rvalue {
if let PlaceRef { local, projection: &[ref proj_base @ .., ProjectionElem::Deref] } =
place.as_ref()
{
if let Some((place_base, ProjectionElem::Deref)) = place.as_ref().last_projection() {
// The dereferenced place must have type `&_`.
let ty = Place::ty_from(local, proj_base, self.body, self.tcx).ty;
let ty = place_base.ty(self.body, self.tcx).ty;
if let ty::Ref(_, _, Mutability::Not) = ty.kind() {
self.optimizations.and_stars.insert(location);
}