about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-02-10 21:26:48 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-02-12 09:42:41 +0000
commit916951efcc51bb7c225a0dba676c34adef620f1d (patch)
tree3ae1d924d6928e84d89335b8e50c53b77036e8b9 /compiler/rustc_middle/src
parentde4d615e6b86f7ef6deacd24610b0678230b8af3 (diff)
downloadrust-916951efcc51bb7c225a0dba676c34adef620f1d.tar.gz
rust-916951efcc51bb7c225a0dba676c34adef620f1d.zip
Make impl_trait_ref into a query also returning more information about the impl
Diffstat (limited to 'compiler/rustc_middle/src')
-rw-r--r--compiler/rustc_middle/src/query/erase.rs5
-rw-r--r--compiler/rustc_middle/src/query/mod.rs4
-rw-r--r--compiler/rustc_middle/src/ty/context.rs9
3 files changed, 14 insertions, 4 deletions
diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs
index a272a51f327..e15a051b33f 100644
--- a/compiler/rustc_middle/src/query/erase.rs
+++ b/compiler/rustc_middle/src/query/erase.rs
@@ -177,8 +177,9 @@ impl EraseType for Option<mir::DestructuredConstant<'_>> {
     type Result = [u8; size_of::<Option<mir::DestructuredConstant<'static>>>()];
 }
 
-impl EraseType for Option<ty::EarlyBinder<ty::TraitRef<'_>>> {
-    type Result = [u8; size_of::<Option<ty::EarlyBinder<ty::TraitRef<'static>>>>()];
+impl EraseType for Option<(ty::EarlyBinder<ty::TraitRef<'_>>, ty::ImplPolarity)> {
+    type Result =
+        [u8; size_of::<Option<(ty::EarlyBinder<ty::TraitRef<'static>>, ty::ImplPolarity)>>()];
 }
 
 impl EraseType for Option<ty::EarlyBinder<Ty<'_>>> {
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs
index 938fba0ed09..59fb198a3da 100644
--- a/compiler/rustc_middle/src/query/mod.rs
+++ b/compiler/rustc_middle/src/query/mod.rs
@@ -846,9 +846,9 @@ rustc_queries! {
         cache_on_disk_if { true }
     }
 
-    /// Given an `impl_id`, return the trait it implements.
+    /// Given an `impl_id`, return the trait it implements along with some header information.
     /// Return `None` if this is an inherent impl.
-    query impl_trait_ref(impl_id: DefId) -> Option<ty::EarlyBinder<ty::TraitRef<'tcx>>> {
+    query impl_trait_header(impl_id: DefId) -> Option<(ty::EarlyBinder<ty::TraitRef<'tcx>>, ty::ImplPolarity)> {
         desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
         cache_on_disk_if { impl_id.is_local() }
         separate_provide_extern
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index b747f0a4fb6..c3b69cee9ed 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -2308,6 +2308,15 @@ impl<'tcx> TyCtxt<'tcx> {
     pub fn module_children_local(self, def_id: LocalDefId) -> &'tcx [ModChild] {
         self.resolutions(()).module_children.get(&def_id).map_or(&[], |v| &v[..])
     }
+
+    /// Given an `impl_id`, return the trait it implements.
+    /// Return `None` if this is an inherent impl.
+    pub fn impl_trait_ref(
+        self,
+        def_id: impl IntoQueryParam<DefId>,
+    ) -> Option<ty::EarlyBinder<ty::TraitRef<'tcx>>> {
+        Some(self.impl_trait_header(def_id)?.0)
+    }
 }
 
 /// Parameter attributes that can only be determined by examining the body of a function instead