]> git.lizzy.rs Git - rust.git/commitdiff
has_deref: simpler comparison, ty fix
authorouz-a <oguz.agcayazi@gmail.com>
Mon, 16 May 2022 13:36:33 +0000 (16:36 +0300)
committerouz-a <oguz.agcayazi@gmail.com>
Fri, 22 Jul 2022 14:35:28 +0000 (17:35 +0300)
compiler/rustc_middle/src/mir/mod.rs
compiler/rustc_mir_transform/src/add_retag.rs

index e2084a12cbe6b283020664aff5449db7a3d652f2..a8408cfe5701915288b722b4be8ce422f20c22d5 100644 (file)
@@ -1464,11 +1464,7 @@ pub fn is_indirect(&self) -> bool {
     /// If MirPhase >= Derefered and if projection contains Deref,
     /// It's guaranteed to be in the first place
     pub fn has_deref(&self) -> bool {
-        if !self.projection.is_empty() && self.projection[0] == PlaceElem::Deref {
-            true
-        } else {
-            false
-        }
+        self.projection.first() == Some(&PlaceElem::Deref)
     }
 
     /// Finds the innermost `Local` from this `Place`, *if* it is either a local itself or
@@ -1546,11 +1542,7 @@ pub fn local_or_deref_local(&self) -> Option<Local> {
     /// If MirPhase >= Derefered and if projection contains Deref,
     /// It's guaranteed to be in the first place
     pub fn has_deref(&self) -> bool {
-        if !self.projection.is_empty() && self.projection[0] == PlaceElem::Deref {
-            true
-        } else {
-            false
-        }
+        self.projection.first() == Some(&PlaceElem::Deref)
     }
 
     /// If this place represents a local variable like `_X` with no
index c91b3044c4fdfd72e506d1a5cf7e7dd3a049b4be..9c5896c4e4aedef2008e849348559d97ffdabb9b 100644 (file)
 /// (Concurrent accesses by other threads are no problem as these are anyway non-atomic
 /// copies.  Data races are UB.)
 fn is_stable(place: PlaceRef<'_>) -> bool {
-    if place.has_deref() {
-        // Which place this evaluates to can change with any memory write,
-        // so cannot assume deref to be stable.
-        return false;
-    } else {
-        return true;
-    }
+    // Which place this evaluates to can change with any memory write,
+    // so cannot assume deref to be stable.
+    !place.has_deref()
 }
 
 /// Determine whether this type may contain a reference (or box), and thus needs retagging.
@@ -82,8 +78,8 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
         };
         let place_base_raw = |place: &Place<'tcx>| {
             // If this is a `Deref`, get the type of what we are deref'ing.
-            if place.ret_deref().is_some() {
-                let ty = place.ty(local_decls, tcx).ty;
+            if place.has_deref() {
+                let ty = &local_decls[place.local].ty;
                 ty.is_unsafe_ptr()
             } else {
                 // Not a deref, and thus not raw.