about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir/tcx.rs
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2024-06-22 12:11:14 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2024-06-22 20:27:08 -0700
commita76e1d9b09ece967c01aafd3f8419f579a7ac5ca (patch)
tree8484fe9b33b82da421a3d3bb7af61bc7626094ce /compiler/rustc_middle/src/mir/tcx.rs
parent9140c9ad5b1279aecfebb6c64b18dbaf67150183 (diff)
downloadrust-a76e1d9b09ece967c01aafd3f8419f579a7ac5ca.tar.gz
rust-a76e1d9b09ece967c01aafd3f8419f579a7ac5ca.zip
Add a `pointee_metadata_ty_or_projection` helper
Diffstat (limited to 'compiler/rustc_middle/src/mir/tcx.rs')
-rw-r--r--compiler/rustc_middle/src/mir/tcx.rs14
1 files changed, 1 insertions, 13 deletions
diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs
index 126387db1d9..412cfc1fc7a 100644
--- a/compiler/rustc_middle/src/mir/tcx.rs
+++ b/compiler/rustc_middle/src/mir/tcx.rs
@@ -289,19 +289,7 @@ impl<'tcx> UnOp {
     pub fn ty(&self, tcx: TyCtxt<'tcx>, arg_ty: Ty<'tcx>) -> Ty<'tcx> {
         match self {
             UnOp::Not | UnOp::Neg => arg_ty,
-            UnOp::PtrMetadata => {
-                let pointee_ty = arg_ty
-                    .builtin_deref(true)
-                    .unwrap_or_else(|| bug!("PtrMetadata of non-dereferenceable ty {arg_ty:?}"));
-                if pointee_ty.is_trivially_sized(tcx) {
-                    tcx.types.unit
-                } else {
-                    let Some(metadata_def_id) = tcx.lang_items().metadata_type() else {
-                        bug!("No metadata_type lang item while looking at {arg_ty:?}")
-                    };
-                    Ty::new_projection(tcx, metadata_def_id, [pointee_ty])
-                }
-            }
+            UnOp::PtrMetadata => arg_ty.pointee_metadata_ty_or_projection(tcx),
         }
     }
 }