about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2022-07-26 07:14:44 +0900
committerGitHub <noreply@github.com>2022-07-26 07:14:44 +0900
commit29892759f6a712b341b35fa66ae485dbe348616f (patch)
treef280fdcbe9f88eccf83b8fbabc33160ccda142ae /compiler/rustc_middle/src
parentc1647e10adb688cb9e5bb069946daa969d48f326 (diff)
parent9f00d836af0a02110a0a47f4d4c7c7182f04574f (diff)
downloadrust-29892759f6a712b341b35fa66ae485dbe348616f.tar.gz
rust-29892759f6a712b341b35fa66ae485dbe348616f.zip
Rollup merge of #97077 - ouz-a:Optimize-backend, r=oli-obk
Simplify some code that depend on Deref

Now that we can assume #97025 works, it's safe to expect Deref is always in the first place of projections. With this, I was able to simplify some code that depended on Deref's place in projections. When we are able to move Derefer before `ElaborateDrops` successfully we will be able to optimize more places.

r? `@oli-obk`
Diffstat (limited to 'compiler/rustc_middle/src')
-rw-r--r--compiler/rustc_middle/src/mir/mod.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs
index 702cc48ff7b..f7311ebdabf 100644
--- a/compiler/rustc_middle/src/mir/mod.rs
+++ b/compiler/rustc_middle/src/mir/mod.rs
@@ -1461,6 +1461,14 @@ impl<'tcx> Place<'tcx> {
         self.projection.iter().any(|elem| elem.is_indirect())
     }
 
+    /// If MirPhase >= Derefered and if projection contains Deref,
+    /// It's guaranteed to be in the first place
+    pub fn has_deref(&self) -> bool {
+        // To make sure this is not accidently used in wrong mir phase
+        debug_assert!(!self.projection[1..].contains(&PlaceElem::Deref));
+        self.projection.first() == Some(&PlaceElem::Deref)
+    }
+
     /// Finds the innermost `Local` from this `Place`, *if* it is either a local itself or
     /// a single deref of a local.
     #[inline(always)]
@@ -1533,6 +1541,12 @@ impl<'tcx> PlaceRef<'tcx> {
         }
     }
 
+    /// If MirPhase >= Derefered and if projection contains Deref,
+    /// It's guaranteed to be in the first place
+    pub fn has_deref(&self) -> bool {
+        self.projection.first() == Some(&PlaceElem::Deref)
+    }
+
     /// If this place represents a local variable like `_X` with no
     /// projections, return `Some(_X)`.
     #[inline]