diff options
| author | ouz-a <oguz.agcayazi@gmail.com> | 2022-05-16 16:36:33 +0300 |
|---|---|---|
| committer | ouz-a <oguz.agcayazi@gmail.com> | 2022-07-22 17:35:28 +0300 |
| commit | 447aaceed717a516bb9f4b295d582f5e2594b83b (patch) | |
| tree | 0966acc535e958e474b8f227ed7362f7d5859530 | |
| parent | c3e1e7a947e65f16b35cbd4af9607fc670474542 (diff) | |
| download | rust-447aaceed717a516bb9f4b295d582f5e2594b83b.tar.gz rust-447aaceed717a516bb9f4b295d582f5e2594b83b.zip | |
has_deref: simpler comparison, ty fix
| -rw-r--r-- | compiler/rustc_middle/src/mir/mod.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_mir_transform/src/add_retag.rs | 14 |
2 files changed, 7 insertions, 19 deletions
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index e2084a12cbe..a8408cfe570 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1464,11 +1464,7 @@ impl<'tcx> Place<'tcx> { /// 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 @@ 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 { - 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 diff --git a/compiler/rustc_mir_transform/src/add_retag.rs b/compiler/rustc_mir_transform/src/add_retag.rs index c91b3044c4f..9c5896c4e4a 100644 --- a/compiler/rustc_mir_transform/src/add_retag.rs +++ b/compiler/rustc_mir_transform/src/add_retag.rs @@ -15,13 +15,9 @@ pub struct AddRetag; /// (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 @@ impl<'tcx> MirPass<'tcx> for AddRetag { }; 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. |
