about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-09-27 11:20:17 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-09-28 16:13:38 +0000
commit6ea2db7c2d78182fabf66a8c6ffc856446e1cf81 (patch)
treeb3f085e5d90b8de6cdfa4eb14a7b1f64c4ee13ad /compiler/rustc_mir_transform/src
parent479fa4a74d74b69c9bc5fc330519a92590f170e4 (diff)
downloadrust-6ea2db7c2d78182fabf66a8c6ffc856446e1cf81.tar.gz
rust-6ea2db7c2d78182fabf66a8c6ffc856446e1cf81.zip
Strip `OpaqueCast` during `RevealAll`.
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/reveal_all.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/reveal_all.rs b/compiler/rustc_mir_transform/src/reveal_all.rs
index cdd208f5c93..6cc0d383119 100644
--- a/compiler/rustc_mir_transform/src/reveal_all.rs
+++ b/compiler/rustc_mir_transform/src/reveal_all.rs
@@ -26,6 +26,25 @@ impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
     }
 
     #[inline]
+    fn visit_place(
+        &mut self,
+        place: &mut Place<'tcx>,
+        _context: PlaceContext,
+        _location: Location,
+    ) {
+        // `OpaqueCast` projections are only needed if there are opaque types on which projections are performed.
+        // After the `RevealAll` pass, all opaque types are replaced with their hidden types, so we don't need these
+        // projections anymore.
+        place.projection = self.tcx.mk_place_elems(
+            &place
+                .projection
+                .into_iter()
+                .filter(|elem| !matches!(elem, ProjectionElem::OpaqueCast(_)))
+                .collect::<Vec<_>>(),
+        );
+    }
+
+    #[inline]
     fn visit_constant(&mut self, constant: &mut ConstOperand<'tcx>, _: Location) {
         // We have to use `try_normalize_erasing_regions` here, since it's
         // possible that we visit impossible-to-satisfy where clauses here,